diff --git a/gradle.properties b/gradle.properties index 74ff0523..7dde7a5a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,9 +4,9 @@ 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 @@ -14,8 +14,8 @@ 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 diff --git a/src/main/java/dev/su5ed/sinytra/connector/loader/ConnectorEarlyLoader.java b/src/main/java/dev/su5ed/sinytra/connector/loader/ConnectorEarlyLoader.java index 89be228e..07e76623 100644 --- a/src/main/java/dev/su5ed/sinytra/connector/loader/ConnectorEarlyLoader.java +++ b/src/main/java/dev/su5ed/sinytra/connector/loader/ConnectorEarlyLoader.java @@ -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 hiddenMods = ConnectorConfig.INSTANCE.get().hiddenMods(); // Find all connector loader mods List mods = LoadingModList.get().getMods().stream() diff --git a/src/main/java/dev/su5ed/sinytra/connector/locator/ConnectorConfig.java b/src/main/java/dev/su5ed/sinytra/connector/locator/ConnectorConfig.java index 7cf89b42..1585c1e0 100644 --- a/src/main/java/dev/su5ed/sinytra/connector/locator/ConnectorConfig.java +++ b/src/main/java/dev/su5ed/sinytra/connector/locator/ConnectorConfig.java @@ -80,8 +80,4 @@ public record ConnectorConfig(int version, List hiddenMods, Multimap getPriorityPatches() { } public static List getPatches() { - final List patches = List.of(Patch.builder() + final List patches = List.of( + Patch.builder() .targetClass("net/minecraft/client/Minecraft") .targetMethod("") .targetInjectionPoint("Lnet/fabricmc/loader/impl/game/minecraft/Hooks;startClient(Ljava/io/File;Ljava/lang/Object;)V") @@ -63,6 +64,12 @@ public static List 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_") @@ -296,6 +303,14 @@ public static List 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") @@ -451,6 +466,13 @@ public static List 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_") diff --git a/src/main/java/dev/su5ed/sinytra/connector/transformer/ModMetadataGenerator.java b/src/main/java/dev/su5ed/sinytra/connector/transformer/ModMetadataGenerator.java index 9397db3e..d81f6b6c 100644 --- a/src/main/java/dev/su5ed/sinytra/connector/transformer/ModMetadataGenerator.java +++ b/src/main/java/dev/su5ed/sinytra/connector/transformer/ModMetadataGenerator.java @@ -50,7 +50,7 @@ public Collection 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; diff --git a/src/mod/java/dev/su5ed/sinytra/connector/mod/ConnectorMod.java b/src/mod/java/dev/su5ed/sinytra/connector/mod/ConnectorMod.java index 80f3abf6..087d8440 100644 --- a/src/mod/java/dev/su5ed/sinytra/connector/mod/ConnectorMod.java +++ b/src/mod/java/dev/su5ed/sinytra/connector/mod/ConnectorMod.java @@ -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; @@ -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; @@ -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) { diff --git a/src/mod/java/dev/su5ed/sinytra/connector/mod/compat/DynamicRegistryPrefixes.java b/src/mod/java/dev/su5ed/sinytra/connector/mod/compat/DynamicRegistryPrefixes.java deleted file mode 100644 index b600f5f9..00000000 --- a/src/mod/java/dev/su5ed/sinytra/connector/mod/compat/DynamicRegistryPrefixes.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.su5ed.sinytra.connector.mod.compat; - -import net.fabricmc.fabric.impl.registry.sync.DynamicRegistriesImpl; -import net.minecraft.resources.ResourceKey; - -public class DynamicRegistryPrefixes { - public static boolean isRegisteredFabricDynamicRegistry(ResourceKey key) { - return DynamicRegistriesImpl.FABRIC_DYNAMIC_REGISTRY_KEYS.stream().anyMatch(key::equals); - } -} diff --git a/src/mod/java/dev/su5ed/sinytra/connector/mod/compat/RegistryUtil.java b/src/mod/java/dev/su5ed/sinytra/connector/mod/compat/RegistryUtil.java new file mode 100644 index 00000000..77667a3f --- /dev/null +++ b/src/mod/java/dev/su5ed/sinytra/connector/mod/compat/RegistryUtil.java @@ -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 void retainFabricClientEntries(ResourceLocation name, ForgeRegistry from, IForgeRegistry to) { + if (FMLLoader.getDist().isClient() && name.equals(PARTICLE_TYPE_REGISTRY)) { + List> list = new ArrayList<>(); + + for (Map.Entry, 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 pair : list) { + RegistryUtil.getNames(from).put(pair.getFirst(), pair.getSecond()); + } + } + } + + private static BiMap getNames(ForgeRegistry registry) { + return (BiMap) uncheck(() -> REGISTRY_NAMES.get(registry)); + } +} diff --git a/src/mod/java/dev/su5ed/sinytra/connector/mod/mixin/client/KeyMappingMixin.java b/src/mod/java/dev/su5ed/sinytra/connector/mod/mixin/client/KeyMappingMixin.java index 85f1c0c7..e3ea1532 100644 --- a/src/mod/java/dev/su5ed/sinytra/connector/mod/mixin/client/KeyMappingMixin.java +++ b/src/mod/java/dev/su5ed/sinytra/connector/mod/mixin/client/KeyMappingMixin.java @@ -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 vanillaKeyMapping; - + private static final ThreadLocal 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); @@ -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>> actualMap = ObfuscationReflectionHelper - .getPrivateValue(KeyMappingLookup.class, MAP, "map"); + .getPrivateValue(KeyMappingLookup.class, MAP, "map"); final var delegate = actualMap.get(KeyModifier.NONE); vanillaKeyMapping = new Map<>() { @Override @@ -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); @@ -126,20 +126,20 @@ public Set keySet() { @Override public Collection values() { return delegate.values() - .stream().flatMap(Collection::stream) - .toList(); + .stream().flatMap(Collection::stream) + .toList(); } @NotNull @Override public Set> entrySet() { return delegate.entrySet().stream() - .filter(e -> !e.getValue().isEmpty()) - .collect(Collectors.toMap( - Entry::getKey, - e -> ((ArrayList) e.getValue()).get(0) - )) - .entrySet(); + .filter(e -> !e.getValue().isEmpty()) + .collect(Collectors.toMap( + Entry::getKey, + e -> ((ArrayList) e.getValue()).get(0) + )) + .entrySet(); } }; } diff --git a/src/mod/java/dev/su5ed/sinytra/connector/mod/mixin/registries/ClientForgeRegistryMixin.java b/src/mod/java/dev/su5ed/sinytra/connector/mod/mixin/registries/ClientForgeRegistryMixin.java new file mode 100644 index 00000000..f5b4d0a2 --- /dev/null +++ b/src/mod/java/dev/su5ed/sinytra/connector/mod/mixin/registries/ClientForgeRegistryMixin.java @@ -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 implements IForgeRegistry { + + @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 from, CallbackInfo ci) { + RegistryUtil.retainFabricClientEntries(name, from, this); + } +} diff --git a/src/mod/java/dev/su5ed/sinytra/connector/mod/mixin/registries/RegistryDataLoaderMixin.java b/src/mod/java/dev/su5ed/sinytra/connector/mod/mixin/registries/RegistryDataLoaderMixin.java index 66a4f06d..4f44316d 100644 --- a/src/mod/java/dev/su5ed/sinytra/connector/mod/mixin/registries/RegistryDataLoaderMixin.java +++ b/src/mod/java/dev/su5ed/sinytra/connector/mod/mixin/registries/RegistryDataLoaderMixin.java @@ -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; @@ -73,7 +73,7 @@ private static String modifyRegistryDirPath(ResourceLocation location, RegistryO private static boolean connector$shouldOmitPrefix(ResourceLocation location, ResourceKey> 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 diff --git a/src/mod/resources/META-INF/asm/fixFieldSignatureChanges.js b/src/mod/resources/META-INF/asm/fixFieldSignatureChanges.js index 20e49f20..d4dbdd63 100644 --- a/src/mod/resources/META-INF/asm/fixFieldSignatureChanges.js +++ b/src/mod/resources/META-INF/asm/fixFieldSignatureChanges.js @@ -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; diff --git a/src/mod/resources/connectormod.mixins.json b/src/mod/resources/connectormod.mixins.json index eff365f0..4e39c8bd 100644 --- a/src/mod/resources/connectormod.mixins.json +++ b/src/mod/resources/connectormod.mixins.json @@ -43,7 +43,8 @@ "recipebook.RecipeBookCategoriesAccessor", "recipebook.RecipeBookCategoriesMixin", "recipebook.RecipeBookManagerMixin", - "registries.MinecraftMixin" + "registries.MinecraftMixin", + "registries.ClientForgeRegistryMixin" ], "server": [ "boot.ServerMainMixin",