Skip to content

Commit

Permalink
reset some client things when changing dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
thiakil committed Sep 2, 2024
1 parent 9cdcd42 commit 59645a9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public void resetClient() {
AdditionsClient.reset();
}

@Override
public void resetClientDimensionChanged() {
}

@Override
public void launchClient() {
AdditionsClient.launch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public String getName() {

@Override
public void resetClient() {
}

@Override
public void resetClientDimensionChanged() {
TurbineMultiblockData.clientRotationMap.clear();
}
}
34 changes: 27 additions & 7 deletions src/main/java/mekanism/client/MekanismClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
}
}
5 changes: 5 additions & 0 deletions src/main/java/mekanism/common/base/IModModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/tools/java/mekanism/tools/common/MekanismTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,8 @@ public String getName() {
@Override
public void resetClient() {
}

@Override
public void resetClientDimensionChanged() {
}
}

0 comments on commit 59645a9

Please sign in to comment.