Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop beta 43 #1006

Merged
merged 13 commits into from
Apr 28, 2024
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=true

# Versions
versionConnector=1.0.0-beta.42
versionAdapter=1.11.39-1.20.1-20240406.124555
versionAdapterDefinition=1.11.47
versionConnector=1.0.0-beta.43
versionAdapter=1.11.55-1.20.1-20240428.153904
versionAdapterDefinition=1.11.55

versionMc=1.20.1
versionForge=47.1.3
versionForgeAutoRenamingTool=1.0.11
versionFabricLoader=2.7.2+0.15.3+1.20.1
versionAccessWidener=2.1.0
versionFabricApi=0.92.0+1.11.5+1.20.1
versionMixin=0.12.10+mixin.0.8.5
versionMixinTransmog=0.4.5+1.20.1
versionMixin=0.12.11+mixin.0.8.5
versionMixinTransmog=0.4.6+1.20.1

# Publishing
curseForgeId=890127
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ public static void init() {
LOGGER.debug("Starting early connector loader setup");
ProgressMeter progress = StartupNotificationManager.addProgressBar("[Connector] Early Setup", 0);
try {
if (ConnectorConfig.usesUnsupportedConfiguration()) {
LOGGER.warn("Outdated connector_global_mod_aliases.json configuration file detected. Please migrate to the new connector.json configuration.");
}
List<String> hiddenMods = ConnectorConfig.INSTANCE.get().hiddenMods();
// Find all connector loader mods
List<ModInfo> mods = LoadingModList.get().getMods().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,4 @@ public record ConnectorConfig(int version, List<String> hiddenMods, Multimap<Str
}
return DEFAULT;
});

public static boolean usesUnsupportedConfiguration() {
return Files.exists(FMLPaths.CONFIGDIR.get().resolve("connector_global_mod_aliases.json"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public static List<Patch> getPriorityPatches() {
}

public static List<Patch> getPatches() {
final List<Object> patches = List.of(Patch.builder()
final List<Object> patches = List.of(
Patch.builder()
.targetClass("net/minecraft/client/Minecraft")
.targetMethod("<init>")
.targetInjectionPoint("Lnet/fabricmc/loader/impl/game/minecraft/Hooks;startClient(Ljava/io/File;Ljava/lang/Object;)V")
Expand All @@ -63,6 +64,12 @@ public static List<Patch> getPatches() {
.injectionPoint("INVOKE", "Lnet/minecraft/world/entity/ai/attributes/AttributeInstance;m_22135_()D")
.putValue("ordinal", 0))
.build(),
Patch.builder()
.targetClass("net/minecraft/world/item/HoeItem")
.targetMethod("m_6225_(Lnet/minecraft/world/item/context/UseOnContext;)Lnet/minecraft/world/InteractionResult;")
.targetInjectionPoint("FIELD", "Lnet/minecraft/world/item/HoeItem;f_41332_:Ljava/util/Map;")
.modifyInjectionPoint("INVOKE", "Lnet/minecraft/world/level/block/state/BlockState;getToolModifiedState(Lnet/minecraft/world/item/context/UseOnContext;Lnet/minecraftforge/common/ToolAction;Z)Lnet/minecraft/world/level/block/state/BlockState;", true)
.build(),
Patch.builder()
.targetClass("net/minecraft/client/KeyMapping")
.targetMethod("m_90837_")
Expand Down Expand Up @@ -296,6 +303,14 @@ public static List<Patch> getPatches() {
.modifyParams(b -> b.insert(0, Type.INT_TYPE).insert(1, Type.INT_TYPE).targetType(ParamTransformTarget.METHOD))
.modifyInjectionPoint("INVOKE", "Lcom/mojang/blaze3d/systems/RenderSystem;disableBlend()V")
.build(),
Patch.builder()
.targetClass("net/minecraft/client/gui/Gui")
.targetMethod("m_280173_(Lnet/minecraft/client/gui/GuiGraphics;)V")
.targetInjectionPoint("Lnet/minecraft/world/food/FoodData;m_38722_()F")
.extractMixin("net/minecraftforge/client/gui/overlay/ForgeGui")
.modifyTarget("renderFood(IILnet/minecraft/client/gui/GuiGraphics;)V")
.modifyParams(b -> b.insert(0, Type.INT_TYPE).insert(1, Type.INT_TYPE).targetType(ParamTransformTarget.METHOD))
.build(),
Patch.builder()
.targetClass("net/minecraft/client/gui/Gui")
.targetMethod("m_280173_(Lnet/minecraft/client/gui/GuiGraphics;)V")
Expand Down Expand Up @@ -451,6 +466,13 @@ public static List<Patch> getPatches() {
adapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D", false);
}))
.build(),
Patch.builder()
.targetClass("net/minecraft/world/entity/LivingEntity")
.targetMethod("updateFallFlying") // updateFallFlying, m_21323_
.targetInjectionPoint("INVOKE", "Lnet/minecraft/world/item/ItemStack;m_41622_(ILnet/minecraft/world/entity/LivingEntity;Ljava/util/function/Consumer;)V") // hurtAndBreak, m_41622_
.extractMixin("net/minecraft/world/item/ElytraItem")
.modifyTarget("elytraFlightTick(Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/entity/LivingEntity;I)Z")
.build(),
Patch.builder()
.targetClass("net/minecraft/server/level/ServerPlayerGameMode")
.targetMethod("m_9280_")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Collection<? extends Entry> getExtras() {

// Generate pack metadata
if (!this.seen) {
byte[] data = generatePackMetadataFile(this.modid);
byte[] data = generatePackMetadataFile(this.modid); // TODO Remove in 1.20.5
extras.add(ResourceEntry.create(RESOURCE, ConnectorUtil.ZIP_TIME, data));
}
return extras;
Expand Down
13 changes: 0 additions & 13 deletions src/mod/java/dev/su5ed/sinytra/connector/mod/ConnectorMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.electronwill.nightconfig.core.file.GenericBuilder;
import com.google.gson.JsonElement;
import dev.su5ed.sinytra.connector.ConnectorUtil;
import dev.su5ed.sinytra.connector.locator.ConnectorConfig;
import dev.su5ed.sinytra.connector.mod.compat.DummyResourceManager;
import dev.su5ed.sinytra.connector.mod.compat.FluidHandlerCompat;
import dev.su5ed.sinytra.connector.mod.compat.LateRenderTypesInit;
Expand All @@ -19,10 +18,6 @@
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.ModList;
import net.minecraftforge.fml.ModLoader;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.ModLoadingStage;
import net.minecraftforge.fml.ModLoadingWarning;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
Expand Down Expand Up @@ -58,14 +53,6 @@ public ConnectorMod() {
if (modList.isLoaded("fabric_object_builder_api_v1")) {
bus.addListener(EventPriority.HIGHEST, LazyEntityAttributes::initializeLazyAttributes);
}

if (ConnectorConfig.usesUnsupportedConfiguration()) {
ModLoader.get().addWarning(new ModLoadingWarning(
ModLoadingContext.get().getActiveContainer().getModInfo(),
ModLoadingStage.CONSTRUCT,
"Outdated connector_global_mod_aliases.json configuration file detected. Please migrate to the new connector.json configuration."
));
}
}

private static void onClientSetup(FMLClientSetupEvent event) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package dev.su5ed.sinytra.connector.mod.compat;

import com.google.common.collect.BiMap;
import com.mojang.datafixers.util.Pair;
import com.mojang.logging.LogUtils;
import dev.su5ed.sinytra.connector.loader.ConnectorEarlyLoader;
import net.fabricmc.fabric.impl.registry.sync.DynamicRegistriesImpl;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.ForgeRegistry;
import net.minecraftforge.registries.IForgeRegistry;
import org.slf4j.Logger;

import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck;

public class RegistryUtil {
private static final VarHandle REGISTRY_NAMES = uncheck(() -> MethodHandles.privateLookupIn(ForgeRegistry.class, MethodHandles.lookup()).findVarHandle(ForgeRegistry.class, "names", BiMap.class));
private static final ResourceLocation PARTICLE_TYPE_REGISTRY = ForgeRegistries.Keys.PARTICLE_TYPES.location();
private static final Logger LOGGER = LogUtils.getLogger();

public static boolean isRegisteredFabricDynamicRegistry(ResourceKey<?> key) {
return DynamicRegistriesImpl.FABRIC_DYNAMIC_REGISTRY_KEYS.stream().anyMatch(key::equals);
}

public static <V> void retainFabricClientEntries(ResourceLocation name, ForgeRegistry<V> from, IForgeRegistry<V> to) {
if (FMLLoader.getDist().isClient() && name.equals(PARTICLE_TYPE_REGISTRY)) {
List<Pair<ResourceLocation, V>> list = new ArrayList<>();

for (Map.Entry<ResourceKey<V>, V> entry : to.getEntries()) {
ResourceLocation location = entry.getKey().location();
if (!from.containsKey(location) && ConnectorEarlyLoader.isConnectorMod(location.getNamespace())) {
list.add(Pair.of(location, entry.getValue()));
}
}

if (!list.isEmpty()) {
LOGGER.info("Connector found {} items to retain in registry {}", list.size(), name);
}

for (Pair<ResourceLocation, V> pair : list) {
RegistryUtil.getNames(from).put(pair.getFirst(), pair.getSecond());
}
}
}

private static <V> BiMap<ResourceLocation, V> getNames(ForgeRegistry<V> registry) {
return (BiMap<ResourceLocation, V>) uncheck(() -> REGISTRY_NAMES.get(registry));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public class KeyMappingMixin {
@Shadow
private static KeyMappingLookup MAP;

@Shadow(remap = false, aliases = "f_90810_")
@Shadow(remap = false, aliases = { "f_90810_", "MAP" })
private static final Map<InputConstants.Key, KeyMapping> vanillaKeyMapping;

private static final ThreadLocal<KeyMapping> KEY_MAPPING_LOCAL = new ThreadLocal<>();

@Inject(method = "set", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/KeyMapping;setDown(Z)V"))
private static void onSetKeyMapping(InputConstants.Key pKey, boolean pHeld, CallbackInfo ci, @Local KeyMapping keyMapping) {
KEY_MAPPING_LOCAL.set(keyMapping);
Expand All @@ -50,7 +50,7 @@ private static void connector_onSetKeyMapping(InputConstants.Key pKey, boolean p
// if they use the field in their code or otherwise reflect (see voxelmap)
// The field is added back through a coremod, and here it is semi-delegated
final EnumMap<KeyModifier, Map<InputConstants.Key, Collection<KeyMapping>>> actualMap = ObfuscationReflectionHelper
.getPrivateValue(KeyMappingLookup.class, MAP, "map");
.getPrivateValue(KeyMappingLookup.class, MAP, "map");
final var delegate = actualMap.get(KeyModifier.NONE);
vanillaKeyMapping = new Map<>() {
@Override
Expand Down Expand Up @@ -99,7 +99,7 @@ public KeyMapping remove(Object key) {
public boolean remove(Object key, Object value) {
Object curValue = get(key);
if (!Objects.equals(curValue, value) ||
(curValue == null && !containsKey(key))) {
(curValue == null && !containsKey(key))) {
return false;
}
MAP.remove((KeyMapping) value);
Expand All @@ -126,20 +126,20 @@ public Set<InputConstants.Key> keySet() {
@Override
public Collection<KeyMapping> values() {
return delegate.values()
.stream().flatMap(Collection::stream)
.toList();
.stream().flatMap(Collection::stream)
.toList();
}

@NotNull
@Override
public Set<Entry<InputConstants.Key, KeyMapping>> entrySet() {
return delegate.entrySet().stream()
.filter(e -> !e.getValue().isEmpty())
.collect(Collectors.toMap(
Entry::getKey,
e -> ((ArrayList<KeyMapping>) e.getValue()).get(0)
))
.entrySet();
.filter(e -> !e.getValue().isEmpty())
.collect(Collectors.toMap(
Entry::getKey,
e -> ((ArrayList<KeyMapping>) e.getValue()).get(0)
))
.entrySet();
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dev.su5ed.sinytra.connector.mod.mixin.registries;

import dev.su5ed.sinytra.connector.mod.compat.RegistryUtil;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.registries.ForgeRegistry;
import net.minecraftforge.registries.IForgeRegistry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ForgeRegistry.class)
public abstract class ClientForgeRegistryMixin<V> implements IForgeRegistry<V> {

@Inject(method = "sync", at = @At(value = "INVOKE", target = "Lcom/google/common/collect/BiMap;clear()V", ordinal = 0), remap = false)
private void retainFabricClientEntries(ResourceLocation name, ForgeRegistry<V> from, CallbackInfo ci) {
RegistryUtil.retainFabricClientEntries(name, from, this);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.su5ed.sinytra.connector.mod.mixin.registries;

import dev.su5ed.sinytra.connector.loader.ConnectorEarlyLoader;
import dev.su5ed.sinytra.connector.mod.compat.DynamicRegistryPrefixes;
import dev.su5ed.sinytra.connector.mod.compat.RegistryUtil;
import net.minecraft.core.Registry;
import net.minecraft.resources.FileToIdConverter;
import net.minecraft.resources.RegistryDataLoader;
Expand Down Expand Up @@ -73,7 +73,7 @@ private static String modifyRegistryDirPath(ResourceLocation location, RegistryO
private static boolean connector$shouldOmitPrefix(ResourceLocation location, ResourceKey<? extends Registry<?>> registryKey, ResourceManager manager) {
String modid = location.getNamespace();
// Fabric mod registries added directly to RegistryDataLoader.WORLDGEN_REGISTRIES should not be prefixed
if (ConnectorEarlyLoader.isConnectorMod(modid) && ModList.get().isLoaded("fabric_registry_sync_v0") && !DynamicRegistryPrefixes.isRegisteredFabricDynamicRegistry(registryKey)) {
if (ConnectorEarlyLoader.isConnectorMod(modid) && ModList.get().isLoaded("fabric_registry_sync_v0") && !RegistryUtil.isRegisteredFabricDynamicRegistry(registryKey)) {
return true;
}
// Check if the registry has been registered
Expand Down
2 changes: 1 addition & 1 deletion src/mod/resources/META-INF/asm/fixFieldSignatureChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function initializeCoreMod() {

// Add the field before the f_90812_ (KeyMapping#CATEGORY_SORT_ORDER) which is the 3rd map
// See https://github.com/Sinytra/Connector/issues/723
node.fields.add(i, new FieldNode(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, 'f_90810_', 'Ljava/util/Map;', null, null));
node.fields.add(i, new FieldNode(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, ASMAPI.mapField('f_90810_'), 'Ljava/util/Map;', null, null));

ASMAPI.log('DEBUG', 'Added field for KeyMapping#MAP (f_90810_) at index ' + (i + 1));
return node;
Expand Down
3 changes: 2 additions & 1 deletion src/mod/resources/connectormod.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"recipebook.RecipeBookCategoriesAccessor",
"recipebook.RecipeBookCategoriesMixin",
"recipebook.RecipeBookManagerMixin",
"registries.MinecraftMixin"
"registries.MinecraftMixin",
"registries.ClientForgeRegistryMixin"
],
"server": [
"boot.ServerMainMixin",
Expand Down
Loading