diff --git a/src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java b/src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java index a6c3ce45..c7c2ac9a 100644 --- a/src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java +++ b/src/main/java/com/mitchej123/hodgepodge/LoadingConfig.java @@ -95,6 +95,7 @@ public class LoadingConfig { public boolean fixThaumcraftGolemMarkerLoading; public boolean fixTimeCommandWithGC; public boolean fixUnfocusedFullscreen; + public boolean fixRenderersWorldLeak; public boolean fixForgeUpdateChecker; public boolean fixUrlDetection; public boolean fixVanillaUnprotectedGetBlock; @@ -289,6 +290,7 @@ public LoadingConfig(File file) { fixThaumcraftAspectSorting = config.get(Category.FIXES.toString(), "fixThaumcraftAspectSorting", true, "Fix Thaumcraft Aspects being sorted by tag instead of by name").getBoolean(); fixThaumcraftGolemMarkerLoading = config.get(Category.FIXES.toString(), "fixThaumcraftGolemMarkerLoading", true, "Fix golem's marker loading failure when dimensionId larger than MAX_BYTE").getBoolean(); fixUnfocusedFullscreen = config.get(Category.FIXES.toString(), "fixUnfocusedFullscreen", true, "Fix exiting fullscreen when you tab out of the game").getBoolean(); + fixRenderersWorldLeak = config.get(Category.FIXES.toString(), "fixRenderersWorldLeak", true, "Fix EffectRenderer and RenderGlobal leaking world instance when leaving world").getBoolean(); fixUrlDetection = config.get(Category.FIXES.toString(), "fixUrlDetection", true, "Fix URISyntaxException in forge.").getBoolean(); fixVanillaUnprotectedGetBlock = config.get(Category.FIXES.toString(), "fixVanillaUnprotectedGetBlock", true, "Fixes various unchecked vanilla getBlock() methods").getBoolean(); fixVillageUncheckedGetBlock = config.get(Category.FIXES.toString(), "fixVillageUncheckedGetBlock", true, "Fixes village unchecked getBlock() calls").getBoolean(); diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java b/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java index 59543e85..d98bcb2e 100644 --- a/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java @@ -173,6 +173,9 @@ public enum Mixins { FIX_UNFOCUSED_FULLSCREEN(new Builder("Fix Unfocused Fullscreen").setPhase(Phase.EARLY) .addMixinClasses("minecraft.MixinMinecraft_UnfocusedFullscreen").setSide(Side.CLIENT) .setApplyIf(() -> Common.config.fixUnfocusedFullscreen).addTargetedMod(TargetedMod.VANILLA)), + FIX_RENDERERS_WORLD_LEAK(new Builder("Fix Renderers World Leak").setPhase(Phase.EARLY) + .addMixinClasses("minecraft.MixinMinecraft_ClearRenderersWorldLeak").setSide(Side.CLIENT) + .setApplyIf(() -> Common.config.fixRenderersWorldLeak).addTargetedMod(TargetedMod.VANILLA)), FIX_OPTIFINE_CHUNKLOADING_CRASH(new Builder("Fix Optifine Chunkloading Crash").setPhase(Phase.EARLY) .setApplyIf(() -> Common.config.fixOptifineChunkLoadingCrash).setSide(Side.CLIENT) .addTargetedMod(TargetedMod.VANILLA).addTargetedMod(TargetedMod.OPTIFINE) diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinMinecraft_ClearRenderersWorldLeak.java b/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinMinecraft_ClearRenderersWorldLeak.java new file mode 100644 index 00000000..0453ecd2 --- /dev/null +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinMinecraft_ClearRenderersWorldLeak.java @@ -0,0 +1,41 @@ +package com.mitchej123.hodgepodge.mixins.early.minecraft; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.particle.EffectRenderer; +import net.minecraft.client.renderer.RenderGlobal; + +import org.objectweb.asm.Opcodes; +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; + +@Mixin(Minecraft.class) +public abstract class MixinMinecraft_ClearRenderersWorldLeak { + + @Shadow + public EffectRenderer effectRenderer; + + @Shadow + public RenderGlobal renderGlobal; + + @Inject( + method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", + at = @At( + value = "FIELD", + target = "Lnet/minecraft/client/Minecraft;theWorld:Lnet/minecraft/client/multiplayer/WorldClient;", + opcode = Opcodes.PUTFIELD)) + private void hodgepodge$fixRenderersWorldLeak(WorldClient worldClient, String loadingMessage, CallbackInfo ci) { + if (worldClient == null) { + if (renderGlobal != null) { + renderGlobal.setWorldAndLoadRenderers(null); + } + + if (effectRenderer != null) { + effectRenderer.clearEffects(null); + } + } + } +}