From c269cbedac7e6cd0b689168af7d6c5892905f3ba Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sun, 26 Feb 2023 20:13:28 -0500 Subject: [PATCH] Patch VanillaPackResources.getResource since it's still an issue --- .../core/config/ModernFixEarlyConfig.java | 2 +- .../VanillaPackResourcesMixin.java | 36 +++++++++++++++++++ src/main/resources/modernfix.mixins.json | 1 + 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/embeddedt/modernfix/mixin/perf/modern_resourcepacks/VanillaPackResourcesMixin.java diff --git a/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java b/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java index 3065eec5..93a70702 100644 --- a/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java +++ b/src/main/java/org/embeddedt/modernfix/core/config/ModernFixEarlyConfig.java @@ -17,7 +17,7 @@ public class ModernFixEarlyConfig { // Defines the default rules which can be configured by the user or other mods. // You must manually add a rule for any new mixins not covered by an existing package rule. this.addMixinRule("core", true); // TODO: Don't actually allow the user to disable this - this.addMixinRule("perf.modern_resourcepacks", false); + this.addMixinRule("perf.modern_resourcepacks", true); this.addMixinRule("feature.branding", true); this.addMixinRule("feature.measure_time", true); this.addMixinRule("feature.reduce_loading_screen_freezes", false); diff --git a/src/main/java/org/embeddedt/modernfix/mixin/perf/modern_resourcepacks/VanillaPackResourcesMixin.java b/src/main/java/org/embeddedt/modernfix/mixin/perf/modern_resourcepacks/VanillaPackResourcesMixin.java new file mode 100644 index 00000000..8fc0086a --- /dev/null +++ b/src/main/java/org/embeddedt/modernfix/mixin/perf/modern_resourcepacks/VanillaPackResourcesMixin.java @@ -0,0 +1,36 @@ +package org.embeddedt.modernfix.mixin.perf.modern_resourcepacks; + +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.PackType; +import net.minecraft.server.packs.VanillaPackResources; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Map; + +@Mixin(VanillaPackResources.class) +public class VanillaPackResourcesMixin { + @Shadow @Final private static Map ROOT_DIR_BY_TYPE; + + /** + * @author embeddedt + * @reason avoid going through the module class loader when we know exactly what path this resource should come + * from + */ + @Overwrite + protected InputStream getResourceAsStream(PackType type, ResourceLocation location) { + Path rootPath = ROOT_DIR_BY_TYPE.get(type); + Path targetPath = rootPath.resolve(location.getNamespace() + "/" + location.getPath()); + try { + return Files.newInputStream(targetPath); + } catch(IOException e) { + return null; + } + } +} diff --git a/src/main/resources/modernfix.mixins.json b/src/main/resources/modernfix.mixins.json index fab55cc2..772b9c46 100644 --- a/src/main/resources/modernfix.mixins.json +++ b/src/main/resources/modernfix.mixins.json @@ -7,6 +7,7 @@ "refmap": "modernfix.refmap.json", "mixins": [ "bugfix.edge_chunk_not_saved.ChunkManagerMixin", + "perf.modern_resourcepacks.VanillaPackResourcesMixin", "perf.remove_biome_temperature_cache.BiomeMixin", "perf.reduce_blockstate_cache_rebuilds.GameDataMixin", "perf.reduce_blockstate_cache_rebuilds.BlockCallbacksMixin",