From 59645a938d415495461c71b7b529ed546d5338ad Mon Sep 17 00:00:00 2001 From: Thiakil Date: Mon, 2 Sep 2024 13:10:55 +0800 Subject: [PATCH] reset some client things when changing dimension --- .../additions/common/MekanismAdditions.java | 4 +++ .../generators/common/MekanismGenerators.java | 4 +++ .../java/mekanism/client/MekanismClient.java | 34 +++++++++++++++---- .../java/mekanism/common/base/IModModule.java | 5 +++ .../mekanism/tools/common/MekanismTools.java | 4 +++ 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/additions/java/mekanism/additions/common/MekanismAdditions.java b/src/additions/java/mekanism/additions/common/MekanismAdditions.java index d5d3587b40f..53e8e88c46d 100644 --- a/src/additions/java/mekanism/additions/common/MekanismAdditions.java +++ b/src/additions/java/mekanism/additions/common/MekanismAdditions.java @@ -94,6 +94,10 @@ public void resetClient() { AdditionsClient.reset(); } + @Override + public void resetClientDimensionChanged() { + } + @Override public void launchClient() { AdditionsClient.launch(); diff --git a/src/generators/java/mekanism/generators/common/MekanismGenerators.java b/src/generators/java/mekanism/generators/common/MekanismGenerators.java index 45672ad61a9..0366ea918e2 100644 --- a/src/generators/java/mekanism/generators/common/MekanismGenerators.java +++ b/src/generators/java/mekanism/generators/common/MekanismGenerators.java @@ -134,6 +134,10 @@ public String getName() { @Override public void resetClient() { + } + + @Override + public void resetClientDimensionChanged() { TurbineMultiblockData.clientRotationMap.clear(); } } diff --git a/src/main/java/mekanism/client/MekanismClient.java b/src/main/java/mekanism/client/MekanismClient.java index 068d2528b8c..5149dab0a94 100644 --- a/src/main/java/mekanism/client/MekanismClient.java +++ b/src/main/java/mekanism/client/MekanismClient.java @@ -19,8 +19,10 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import net.neoforged.api.distmarker.Dist; +import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.ModContainer; import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.client.event.ClientPlayerNetworkEvent; import net.neoforged.neoforge.client.gui.ConfigurationScreen; import net.neoforged.neoforge.client.gui.IConfigScreenFactory; import org.jetbrains.annotations.Nullable; @@ -50,22 +52,33 @@ public static void updateKey(boolean pressed, int type) { } } + /** + * Reset things that aren't needed between levels or would leak + */ + public static void resetDimensionChange() { + Mekanism.playerState.clear(true); + Mekanism.activeVibrators.clear(); + RadiationManager.get().resetClient(); + RenderSPS.clearBoltRenderers(); + TransmitterNetworkRegistry.getInstance().clearClientNetworks(); + RenderTickHandler.clearQueued(); + + for (IModModule module : Mekanism.modulesLoaded) { + module.resetClientDimensionChanged(); + } + } + public static void reset() { clientSecurityMap.clear(); clientUUIDMap.clear(); ClientTickHandler.portableTeleports.clear(); ClientTickHandler.visionEnhancement = false; - - Mekanism.playerState.clear(true); - Mekanism.activeVibrators.clear(); - RadiationManager.get().resetClient(); SoundHandler.radiationSoundMap.clear(); - RenderSPS.clearBoltRenderers(); - TransmitterNetworkRegistry.getInstance().clearClientNetworks(); - RenderTickHandler.clearQueued(); MekanismRecipeType.clearCache(); + resetDimensionChange(); + for (IModModule module : Mekanism.modulesLoaded) { module.resetClient(); } @@ -86,4 +99,11 @@ public static Level tryGetClientWorld() { public static Player tryGetClientPlayer() { return Minecraft.getInstance().player; } + + @SubscribeEvent + public static void onCloneRespawn(ClientPlayerNetworkEvent.Clone event) { + if (event.getOldPlayer().level() != event.getNewPlayer().level()) { + resetDimensionChange(); + } + } } \ No newline at end of file diff --git a/src/main/java/mekanism/common/base/IModModule.java b/src/main/java/mekanism/common/base/IModModule.java index e7211dcaba6..db5e7824ca5 100644 --- a/src/main/java/mekanism/common/base/IModModule.java +++ b/src/main/java/mekanism/common/base/IModModule.java @@ -29,6 +29,11 @@ public interface IModModule { */ void resetClient(); + /** + * Called when dimension changed or returns to main menu. + */ + void resetClientDimensionChanged(); + /** * Called during the first tick after joining a game. */ diff --git a/src/tools/java/mekanism/tools/common/MekanismTools.java b/src/tools/java/mekanism/tools/common/MekanismTools.java index 9ee8a02958a..9ec2f0c427b 100644 --- a/src/tools/java/mekanism/tools/common/MekanismTools.java +++ b/src/tools/java/mekanism/tools/common/MekanismTools.java @@ -64,4 +64,8 @@ public String getName() { @Override public void resetClient() { } + + @Override + public void resetClientDimensionChanged() { + } } \ No newline at end of file