From 02d22fd50cffa3c223927ce694b5436f35a9e03d Mon Sep 17 00:00:00 2001 From: contaria Date: Fri, 9 May 2025 17:10:26 +0200 Subject: [PATCH 1/8] port: 5.1.0 to 1.15.2 --- gradle.properties | 2 +- .../AntiResourceReload.java | 10 ++- .../mixin/MinecraftClientMixin.java | 58 +++++++++++++ .../mixin/MinecraftServerMixin.java | 81 ++++++++++++++----- .../mixin/RecipeBookWidgetMixin.java | 8 +- .../mixin/RecipeManagerAccess.java | 3 +- .../mixin/RecipeManagerMixin.java | 3 +- .../resources/antiresourcereload.mixins.json | 1 + src/main/resources/fabric.mod.json | 2 +- 9 files changed, 138 insertions(+), 30 deletions(-) create mode 100644 src/main/java/me/wurgo/antiresourcereload/mixin/MinecraftClientMixin.java diff --git a/gradle.properties b/gradle.properties index 265f56a..472ac81 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs = -Xmx2G org.gradle.parallel = true org.gradle.caching = true -mod_version = 4.0.3 +mod_version = 5.1.0 target_version = 1.15.2 archives_name = antiresourcereload maven_group = me.wurgo diff --git a/src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java b/src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java index 0f1bc69..cd0aa98 100644 --- a/src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java +++ b/src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java @@ -2,7 +2,6 @@ import com.google.gson.JsonElement; import net.fabricmc.api.ModInitializer; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.loot.LootManager; import net.minecraft.loot.condition.LootConditionManager; import net.minecraft.recipe.RecipeManager; @@ -11,13 +10,14 @@ import net.minecraft.server.function.CommandFunctionManager; import net.minecraft.tag.RegistryTagManager; import net.minecraft.util.Identifier; +import net.minecraft.util.UserCache; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.Map; public class AntiResourceReload implements ModInitializer { - private static final Logger LOGGER = LogManager.getLogger(FabricLoader.getInstance().getModContainer("antiresourcereload").get().getMetadata().getName()); + private static final Logger LOGGER = LogManager.getLogger(); public static ReloadableResourceManager dataManager; public static RecipeManager recipeManager; @@ -27,10 +27,14 @@ public class AntiResourceReload implements ModInitializer { public static ServerAdvancementLoader advancementLoader; public static CommandFunctionManager commandFunctionManager; public static Map recipes; + + public static UserCache userCache; + + public static boolean hasInitializedShapeCache; public static boolean hasSeenRecipes; public static void log(String message) { - LOGGER.info("[" + LOGGER.getName() + "] " + message); + LOGGER.info("[AntiResourceReload] {}", message); } @Override diff --git a/src/main/java/me/wurgo/antiresourcereload/mixin/MinecraftClientMixin.java b/src/main/java/me/wurgo/antiresourcereload/mixin/MinecraftClientMixin.java new file mode 100644 index 0000000..32bd412 --- /dev/null +++ b/src/main/java/me/wurgo/antiresourcereload/mixin/MinecraftClientMixin.java @@ -0,0 +1,58 @@ +package me.wurgo.antiresourcereload.mixin; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.mojang.authlib.GameProfileRepository; +import me.wurgo.antiresourcereload.AntiResourceReload; +import net.minecraft.client.MinecraftClient; +import net.minecraft.server.integrated.IntegratedServer; +import net.minecraft.util.UserCache; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.io.File; + +@Mixin(MinecraftClient.class) +public abstract class MinecraftClientMixin { + + @Shadow + @Nullable + private IntegratedServer server; + + @Inject( + method = "startIntegratedServer", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/network/ClientConnection;connectLocal(Ljava/net/SocketAddress;)Lnet/minecraft/network/ClientConnection;" + ) + ) + private void reloadRecipes(CallbackInfo ci) { + // reloading is done when actually joining the world instead of on world creation because of SeedQueue + if (this.server != null && this.server.getRecipeManager() == AntiResourceReload.recipeManager && AntiResourceReload.hasSeenRecipes) { + ((RecipeManagerAccess) AntiResourceReload.recipeManager).antiresourcereload$apply(AntiResourceReload.recipes, null, null); + AntiResourceReload.hasSeenRecipes = false; + } + } + + @WrapOperation( + method = { + "startIntegratedServer", + "joinWorld" + }, + at = @At( + value = "NEW", + target = "(Lcom/mojang/authlib/GameProfileRepository;Ljava/io/File;)Lnet/minecraft/util/UserCache;" + ), + require = 2 + ) + private UserCache cacheUserCache(GameProfileRepository profileRepository, File cacheFile, Operation original) { + if (AntiResourceReload.userCache == null) { + AntiResourceReload.userCache = original.call(profileRepository, cacheFile); + } + return AntiResourceReload.userCache; + } +} diff --git a/src/main/java/me/wurgo/antiresourcereload/mixin/MinecraftServerMixin.java b/src/main/java/me/wurgo/antiresourcereload/mixin/MinecraftServerMixin.java index 9990884..5c8e915 100644 --- a/src/main/java/me/wurgo/antiresourcereload/mixin/MinecraftServerMixin.java +++ b/src/main/java/me/wurgo/antiresourcereload/mixin/MinecraftServerMixin.java @@ -1,6 +1,9 @@ package me.wurgo.antiresourcereload.mixin; import com.google.common.collect.Lists; +import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import me.wurgo.antiresourcereload.AntiResourceReload; import net.minecraft.loot.LootManager; import net.minecraft.loot.condition.LootConditionManager; @@ -17,42 +20,66 @@ import org.spongepowered.asm.mixin.Mutable; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; import java.util.List; @Mixin(MinecraftServer.class) public abstract class MinecraftServerMixin { - @Shadow protected abstract void reloadDataPacks(LevelProperties levelProperties); - @Mutable @Shadow @Final private ReloadableResourceManager dataManager; - @Mutable @Shadow @Final private RegistryTagManager tagManager; - @Mutable @Shadow @Final private LootConditionManager predicateManager; - @Mutable @Shadow @Final private RecipeManager recipeManager; - @Mutable @Shadow @Final private LootManager lootManager; - @Mutable @Shadow @Final private CommandFunctionManager commandFunctionManager; - @Mutable @Shadow @Final private ServerAdvancementLoader advancementLoader; + @Shadow + @Final + private static Logger LOGGER; - @Shadow @Final private static Logger LOGGER; - @Shadow @Final private ResourcePackManager dataPackManager; + @Shadow + @Final + private ResourcePackManager dataPackManager; - @Redirect( + @Mutable + @Shadow + @Final + private ReloadableResourceManager dataManager; + @Mutable + @Shadow + @Final + private RegistryTagManager tagManager; + @Mutable + @Shadow + @Final + private LootConditionManager predicateManager; + @Mutable + @Shadow + @Final + private RecipeManager recipeManager; + @Mutable + @Shadow + @Final + private LootManager lootManager; + @Mutable + @Shadow + @Final + private CommandFunctionManager commandFunctionManager; + @Mutable + @Shadow + @Final + private ServerAdvancementLoader advancementLoader; + + @WrapOperation( method = "loadWorldDataPacks", at = @At( value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;reloadDataPacks(Lnet/minecraft/world/level/LevelProperties;)V" ) ) - private void antiresourcereload_cachedReload(MinecraftServer instance, LevelProperties levelProperties) { - if (levelProperties.getEnabledDataPacks().size() + levelProperties.getDisabledDataPacks().size() != 0) { + private void cachedReload(MinecraftServer server, LevelProperties properties, Operation original) { + if (!properties.getEnabledDataPacks().isEmpty() || !properties.getDisabledDataPacks().isEmpty()) { AntiResourceReload.log("Using data-packs, reloading."); - this.reloadDataPacks(levelProperties); + original.call(server, properties); return; } - + if (AntiResourceReload.dataManager == null) { AntiResourceReload.log("Cached resources unavailable, reloading & caching."); AntiResourceReload.dataManager = this.dataManager; - this.reloadDataPacks(levelProperties); + original.call(server, properties); AntiResourceReload.tagManager = this.tagManager; AntiResourceReload.predicateManager = this.predicateManager; AntiResourceReload.recipeManager = this.recipeManager; @@ -68,16 +95,13 @@ private void antiresourcereload_cachedReload(MinecraftServer instance, LevelProp this.lootManager = AntiResourceReload.lootManager; this.commandFunctionManager = AntiResourceReload.commandFunctionManager; this.advancementLoader = AntiResourceReload.advancementLoader; - if (AntiResourceReload.hasSeenRecipes) { - ((RecipeManagerAccess) this.recipeManager).invokeApply(AntiResourceReload.recipes, null, null); - } // should only be the vanilla pack // logic taken from MinecraftServer#reloadDataPacks List list = Lists.newArrayList(this.dataPackManager.getEnabledProfiles()); for (ResourcePackProfile resourcePackProfile : this.dataPackManager.getProfiles()) { - if (!levelProperties.getDisabledDataPacks().contains(resourcePackProfile.getName()) && !list.contains(resourcePackProfile)) { + if (!properties.getDisabledDataPacks().contains(resourcePackProfile.getName()) && !list.contains(resourcePackProfile)) { LOGGER.info("Found new data pack {}, loading it automatically", resourcePackProfile.getName()); resourcePackProfile.getInitialPosition().insert(list, resourcePackProfile, profile -> profile, false); } @@ -85,4 +109,19 @@ private void antiresourcereload_cachedReload(MinecraftServer instance, LevelProp this.dataPackManager.setEnabledProfiles(list); } } + + @WrapWithCondition( + method = "loadWorldDataPacks", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/server/MinecraftServer;method_24154()V" + ) + ) + private boolean skipInitializingShapeCache(MinecraftServer server) { + if (!AntiResourceReload.hasInitializedShapeCache) { + AntiResourceReload.hasInitializedShapeCache = true; + return true; + } + return false; + } } diff --git a/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeBookWidgetMixin.java b/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeBookWidgetMixin.java index e1ebf70..dbc5cb4 100644 --- a/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeBookWidgetMixin.java +++ b/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeBookWidgetMixin.java @@ -9,8 +9,12 @@ @Mixin(RecipeBookWidget.class) public class RecipeBookWidgetMixin { - @Inject(method = "initialize", at = @At("HEAD")) - public void antiresourcereload_updateHasSeenRecipes(CallbackInfo ci) { + + @Inject( + method = "initialize", + at = @At("HEAD") + ) + public void updateHasSeenRecipes(CallbackInfo ci) { AntiResourceReload.hasSeenRecipes = true; } } diff --git a/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeManagerAccess.java b/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeManagerAccess.java index e4de2e9..86d74dd 100644 --- a/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeManagerAccess.java +++ b/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeManagerAccess.java @@ -12,5 +12,6 @@ @Mixin(RecipeManager.class) public interface RecipeManagerAccess { - @Invoker void invokeApply(Map map, ResourceManager resourceManager, Profiler profiler); + @Invoker("apply") + void antiresourcereload$apply(Map map, ResourceManager resourceManager, Profiler profiler); } diff --git a/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeManagerMixin.java b/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeManagerMixin.java index 41e2f43..f2489cf 100644 --- a/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeManagerMixin.java +++ b/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeManagerMixin.java @@ -15,11 +15,12 @@ @Mixin(RecipeManager.class) public class RecipeManagerMixin { + @Inject( method = "apply(Ljava/util/Map;Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/util/profiler/Profiler;)V", at = @At("HEAD") ) - private void antiresourcereload_setRecipes(Map map, ResourceManager resourceManager, Profiler profiler, CallbackInfo ci) { + private void setRecipes(Map map, ResourceManager resourceManager, Profiler profiler, CallbackInfo ci) { if (AntiResourceReload.dataManager != null && AntiResourceReload.recipeManager == null) { AntiResourceReload.recipes = map; } diff --git a/src/main/resources/antiresourcereload.mixins.json b/src/main/resources/antiresourcereload.mixins.json index cea5c20..f3258f4 100644 --- a/src/main/resources/antiresourcereload.mixins.json +++ b/src/main/resources/antiresourcereload.mixins.json @@ -4,6 +4,7 @@ "package": "me.wurgo.antiresourcereload.mixin", "compatibilityLevel": "JAVA_8", "client": [ + "MinecraftClientMixin", "MinecraftServerMixin", "RecipeBookWidgetMixin", "RecipeManagerAccess", diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 306b5d8..1e912e0 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -9,7 +9,7 @@ ], "contributors": [ "Pixfumy", - "KingContaria", + "contaria", "Ronkzinho", "jan-leila", "VoidXWalker" From 8f0dcf1c91a3c67542aef0b073c2a0d889342d1d Mon Sep 17 00:00:00 2001 From: contaria Date: Fri, 9 May 2025 22:21:42 +0200 Subject: [PATCH 2/8] feature: cache command manager --- .../AntiResourceReload.java | 3 +++ .../mixin/IntegratedServerMixin.java | 27 +++++++++++++++++++ .../resources/antiresourcereload.mixins.json | 1 + 3 files changed, 31 insertions(+) create mode 100644 src/main/java/me/wurgo/antiresourcereload/mixin/IntegratedServerMixin.java diff --git a/src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java b/src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java index cd0aa98..b064994 100644 --- a/src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java +++ b/src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java @@ -7,6 +7,7 @@ import net.minecraft.recipe.RecipeManager; import net.minecraft.resource.ReloadableResourceManager; import net.minecraft.server.ServerAdvancementLoader; +import net.minecraft.server.command.CommandManager; import net.minecraft.server.function.CommandFunctionManager; import net.minecraft.tag.RegistryTagManager; import net.minecraft.util.Identifier; @@ -28,6 +29,8 @@ public class AntiResourceReload implements ModInitializer { public static CommandFunctionManager commandFunctionManager; public static Map recipes; + public static CommandManager commandManager; + public static UserCache userCache; public static boolean hasInitializedShapeCache; diff --git a/src/main/java/me/wurgo/antiresourcereload/mixin/IntegratedServerMixin.java b/src/main/java/me/wurgo/antiresourcereload/mixin/IntegratedServerMixin.java new file mode 100644 index 0000000..be2beba --- /dev/null +++ b/src/main/java/me/wurgo/antiresourcereload/mixin/IntegratedServerMixin.java @@ -0,0 +1,27 @@ +package me.wurgo.antiresourcereload.mixin; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import me.wurgo.antiresourcereload.AntiResourceReload; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.integrated.IntegratedServer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(IntegratedServer.class) +public abstract class IntegratedServerMixin { + + @WrapOperation( + method = "", + at = @At( + value = "NEW", + target = "(Z)Lnet/minecraft/server/command/CommandManager;" + ) + ) + private static CommandManager cacheCommandManager(boolean isDedicatedServer, Operation original) { + if (AntiResourceReload.commandManager == null) { + AntiResourceReload.commandManager = original.call(isDedicatedServer); + } + return AntiResourceReload.commandManager; + } +} diff --git a/src/main/resources/antiresourcereload.mixins.json b/src/main/resources/antiresourcereload.mixins.json index f3258f4..a65eace 100644 --- a/src/main/resources/antiresourcereload.mixins.json +++ b/src/main/resources/antiresourcereload.mixins.json @@ -4,6 +4,7 @@ "package": "me.wurgo.antiresourcereload.mixin", "compatibilityLevel": "JAVA_8", "client": [ + "IntegratedServerMixin", "MinecraftClientMixin", "MinecraftServerMixin", "RecipeBookWidgetMixin", From 7797739b7e9859b2347a88deee89b55072f8834e Mon Sep 17 00:00:00 2001 From: contaria Date: Sat, 10 May 2025 18:20:02 +0200 Subject: [PATCH 3/8] change: remove log message on initialization --- .../me/wurgo/antiresourcereload/AntiResourceReload.java | 8 +------- .../antiresourcereload/mixin/RecipeBookWidgetMixin.java | 2 +- .../antiresourcereload/mixin/RecipeManagerMixin.java | 2 +- src/main/resources/fabric.mod.json | 5 ----- 4 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java b/src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java index b064994..1841eec 100644 --- a/src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java +++ b/src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java @@ -1,7 +1,6 @@ package me.wurgo.antiresourcereload; import com.google.gson.JsonElement; -import net.fabricmc.api.ModInitializer; import net.minecraft.loot.LootManager; import net.minecraft.loot.condition.LootConditionManager; import net.minecraft.recipe.RecipeManager; @@ -17,7 +16,7 @@ import java.util.Map; -public class AntiResourceReload implements ModInitializer { +public class AntiResourceReload { private static final Logger LOGGER = LogManager.getLogger(); public static ReloadableResourceManager dataManager; @@ -39,9 +38,4 @@ public class AntiResourceReload implements ModInitializer { public static void log(String message) { LOGGER.info("[AntiResourceReload] {}", message); } - - @Override - public void onInitialize() { - log("Initializing."); - } } diff --git a/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeBookWidgetMixin.java b/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeBookWidgetMixin.java index dbc5cb4..93257dd 100644 --- a/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeBookWidgetMixin.java +++ b/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeBookWidgetMixin.java @@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(RecipeBookWidget.class) -public class RecipeBookWidgetMixin { +public abstract class RecipeBookWidgetMixin { @Inject( method = "initialize", diff --git a/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeManagerMixin.java b/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeManagerMixin.java index f2489cf..710b156 100644 --- a/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeManagerMixin.java +++ b/src/main/java/me/wurgo/antiresourcereload/mixin/RecipeManagerMixin.java @@ -14,7 +14,7 @@ import java.util.Map; @Mixin(RecipeManager.class) -public class RecipeManagerMixin { +public abstract class RecipeManagerMixin { @Inject( method = "apply(Ljava/util/Map;Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/util/profiler/Profiler;)V", diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 1e912e0..60aece6 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -22,11 +22,6 @@ "mixins": [ "antiresourcereload.mixins.json" ], - "entrypoints": { - "main": [ - "me.wurgo.antiresourcereload.AntiResourceReload" - ] - }, "depends": { "minecraft": [ "1.15.x", From 40ee6db665a88d95fc72fa248f28cb9ecfbdce82 Mon Sep 17 00:00:00 2001 From: contaria Date: Sat, 10 May 2025 21:22:00 +0200 Subject: [PATCH 4/8] upgradle: update gradle, loom and fabricloader had some refmap issues before, fixed now not sure if thats because the update was needed or because it regenerated some caches --- gradle/libs.versions.toml | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 624cd74..d194b1c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,8 +1,8 @@ [versions] minecraft = "1.15.2" yarn_mappings = "1.15.2+build.17" -fabric_loader = "0.15.7" -loom = "1.5-SNAPSHOT" +fabric_loader = "0.16.10" +loom = "1.9-SNAPSHOT" vineflower = "1.10.0-SNAPSHOT" [libraries] diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2ea3535..7cf748e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-all.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME From 5723685bb7c041225c8235cc1b841604174d2e33 Mon Sep 17 00:00:00 2001 From: contaria Date: Fri, 22 Nov 2024 11:06:16 +0100 Subject: [PATCH 5/8] feature: cache structures --- .../AntiResourceReload.java | 7 +++- .../mixin/MinecraftServerMixin.java | 4 +- .../mixin/StructureManagerMixin.java | 38 +++++++++++++++++++ .../resources/antiresourcereload.mixins.json | 3 +- 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 src/main/java/me/wurgo/antiresourcereload/mixin/StructureManagerMixin.java diff --git a/src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java b/src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java index 1841eec..7cb9b7b 100644 --- a/src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java +++ b/src/main/java/me/wurgo/antiresourcereload/AntiResourceReload.java @@ -8,12 +8,15 @@ import net.minecraft.server.ServerAdvancementLoader; import net.minecraft.server.command.CommandManager; import net.minecraft.server.function.CommandFunctionManager; +import net.minecraft.structure.Structure; import net.minecraft.tag.RegistryTagManager; import net.minecraft.util.Identifier; import net.minecraft.util.UserCache; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.Collections; +import java.util.HashMap; import java.util.Map; public class AntiResourceReload { @@ -30,11 +33,13 @@ public class AntiResourceReload { public static CommandManager commandManager; + public static final Map structures = Collections.synchronizedMap(new HashMap<>()); + public static UserCache userCache; public static boolean hasInitializedShapeCache; public static boolean hasSeenRecipes; - + public static void log(String message) { LOGGER.info("[AntiResourceReload] {}", message); } diff --git a/src/main/java/me/wurgo/antiresourcereload/mixin/MinecraftServerMixin.java b/src/main/java/me/wurgo/antiresourcereload/mixin/MinecraftServerMixin.java index 5c8e915..14aadae 100644 --- a/src/main/java/me/wurgo/antiresourcereload/mixin/MinecraftServerMixin.java +++ b/src/main/java/me/wurgo/antiresourcereload/mixin/MinecraftServerMixin.java @@ -8,7 +8,9 @@ import net.minecraft.loot.LootManager; import net.minecraft.loot.condition.LootConditionManager; import net.minecraft.recipe.RecipeManager; -import net.minecraft.resource.*; +import net.minecraft.resource.ReloadableResourceManager; +import net.minecraft.resource.ResourcePackManager; +import net.minecraft.resource.ResourcePackProfile; import net.minecraft.server.MinecraftServer; import net.minecraft.server.ServerAdvancementLoader; import net.minecraft.server.function.CommandFunctionManager; diff --git a/src/main/java/me/wurgo/antiresourcereload/mixin/StructureManagerMixin.java b/src/main/java/me/wurgo/antiresourcereload/mixin/StructureManagerMixin.java new file mode 100644 index 0000000..7b8d782 --- /dev/null +++ b/src/main/java/me/wurgo/antiresourcereload/mixin/StructureManagerMixin.java @@ -0,0 +1,38 @@ +package me.wurgo.antiresourcereload.mixin; + +import me.wurgo.antiresourcereload.AntiResourceReload; +import net.minecraft.server.MinecraftServer; +import net.minecraft.structure.Structure; +import net.minecraft.structure.StructureManager; +import net.minecraft.util.Identifier; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; + +import java.util.function.Function; + +@Mixin(StructureManager.class) +public abstract class StructureManagerMixin { + @Shadow + @Final + private MinecraftServer server; + + @ModifyArg( + method = "getStructure", + at = @At( + value = "INVOKE", + target = "Ljava/util/Map;computeIfAbsent(Ljava/lang/Object;Ljava/util/function/Function;)Ljava/lang/Object;" + ), + index = 1 + ) + private Function getCachedStructure(Function function) { + return id -> { + if (AntiResourceReload.dataManager == this.server.getDataManager()) { + return AntiResourceReload.structures.computeIfAbsent(id, function); + } + return function.apply(id); + }; + } +} diff --git a/src/main/resources/antiresourcereload.mixins.json b/src/main/resources/antiresourcereload.mixins.json index a65eace..c1fc16a 100644 --- a/src/main/resources/antiresourcereload.mixins.json +++ b/src/main/resources/antiresourcereload.mixins.json @@ -9,7 +9,8 @@ "MinecraftServerMixin", "RecipeBookWidgetMixin", "RecipeManagerAccess", - "RecipeManagerMixin" + "RecipeManagerMixin", + "StructureManagerMixin" ], "injectors": { "defaultRequire": 1 From 981abc18865cb2bef9a1fa6de7239e3bd8ed54ad Mon Sep 17 00:00:00 2001 From: contaria Date: Fri, 7 Feb 2025 23:24:00 +0100 Subject: [PATCH 6/8] feature: cache default pack metadata --- .../mixin/DefaultResourcePackMixin.java | 28 +++++++++++++++++++ .../resources/antiresourcereload.mixins.json | 1 + 2 files changed, 29 insertions(+) create mode 100644 src/main/java/me/wurgo/antiresourcereload/mixin/DefaultResourcePackMixin.java diff --git a/src/main/java/me/wurgo/antiresourcereload/mixin/DefaultResourcePackMixin.java b/src/main/java/me/wurgo/antiresourcereload/mixin/DefaultResourcePackMixin.java new file mode 100644 index 0000000..6e2932f --- /dev/null +++ b/src/main/java/me/wurgo/antiresourcereload/mixin/DefaultResourcePackMixin.java @@ -0,0 +1,28 @@ +package me.wurgo.antiresourcereload.mixin; + +import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import net.minecraft.resource.DefaultResourcePack; +import net.minecraft.resource.metadata.PackResourceMetadata; +import net.minecraft.resource.metadata.ResourceMetadataReader; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; + +@Mixin(DefaultResourcePack.class) +public abstract class DefaultResourcePackMixin { + @Nullable + @Unique + private static PackResourceMetadata METADATA; + + @WrapMethod(method = "parseMetadata") + private Object cacheMetadata(ResourceMetadataReader reader, Operation original) { + if (reader != PackResourceMetadata.READER) { + return original.call(reader); + } + if (METADATA == null) { + METADATA = (PackResourceMetadata) original.call(reader); + } + return METADATA; + } +} diff --git a/src/main/resources/antiresourcereload.mixins.json b/src/main/resources/antiresourcereload.mixins.json index c1fc16a..3c9d11f 100644 --- a/src/main/resources/antiresourcereload.mixins.json +++ b/src/main/resources/antiresourcereload.mixins.json @@ -4,6 +4,7 @@ "package": "me.wurgo.antiresourcereload.mixin", "compatibilityLevel": "JAVA_8", "client": [ + "DefaultResourcePackMixin", "IntegratedServerMixin", "MinecraftClientMixin", "MinecraftServerMixin", From cf23c10d42767c47e33edc18210a7efdfb22d1a4 Mon Sep 17 00:00:00 2001 From: contaria Date: Thu, 12 Jun 2025 01:56:30 +0200 Subject: [PATCH 7/8] metadata: update links --- src/main/resources/fabric.mod.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 60aece6..644db99 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -15,7 +15,9 @@ "VoidXWalker" ], "contact": { - "homepage": "https://github.com/wurgo" + "homepage": "https://github.com/wurgo", + "sources": "https://github.com/Minecraft-Java-Edition-Speedrunning/antiresourcereload", + "issues": "https://github.com/Minecraft-Java-Edition-Speedrunning/antiresourcereload/issues" }, "license": "MIT", "environment": "client", From d94e617f8e6217546e9ebfc2ae4176b89267169a Mon Sep 17 00:00:00 2001 From: contaria Date: Tue, 24 Jun 2025 18:18:04 +0200 Subject: [PATCH 8/8] Version 5.2.0 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 472ac81..24d59ec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ org.gradle.jvmargs = -Xmx2G org.gradle.parallel = true org.gradle.caching = true -mod_version = 5.1.0 +mod_version = 5.2.0 target_version = 1.15.2 archives_name = antiresourcereload maven_group = me.wurgo