From bf18a8ee60663dc9664fb89eedf20c0f74f71f09 Mon Sep 17 00:00:00 2001 From: Lyfts <127234178+Lyfts@users.noreply.github.com> Date: Thu, 5 Sep 2024 16:07:01 +0200 Subject: [PATCH] reset cache clear flags & clear cache when joining new world --- .../com/gtnewhorizons/navigator/ClientProxy.java | 4 ++++ .../com/gtnewhorizons/navigator/EventHandler.java | 15 +++++++++++++++ .../navigator/api/model/layers/LayerManager.java | 10 +++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/gtnewhorizons/navigator/EventHandler.java diff --git a/src/main/java/com/gtnewhorizons/navigator/ClientProxy.java b/src/main/java/com/gtnewhorizons/navigator/ClientProxy.java index 9f627de..138d127 100644 --- a/src/main/java/com/gtnewhorizons/navigator/ClientProxy.java +++ b/src/main/java/com/gtnewhorizons/navigator/ClientProxy.java @@ -5,6 +5,7 @@ import com.gtnewhorizons.navigator.impl.DirtyChunkLayerManager; import cpw.mods.fml.client.registry.ClientRegistry; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; @@ -18,6 +19,9 @@ public void preInit(FMLPreInitializationEvent event) { if (GeneralConfig.enableDebugLayers) { NavigatorApi.registerLayerManager(DirtyChunkLayerManager.INSTANCE); } + FMLCommonHandler.instance() + .bus() + .register(new EventHandler()); } @Override diff --git a/src/main/java/com/gtnewhorizons/navigator/EventHandler.java b/src/main/java/com/gtnewhorizons/navigator/EventHandler.java new file mode 100644 index 0000000..4b682e9 --- /dev/null +++ b/src/main/java/com/gtnewhorizons/navigator/EventHandler.java @@ -0,0 +1,15 @@ +package com.gtnewhorizons.navigator; + +import com.gtnewhorizons.navigator.api.NavigatorApi; +import com.gtnewhorizons.navigator.api.model.layers.LayerManager; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.network.FMLNetworkEvent; + +public class EventHandler { + + @SubscribeEvent + public void onClientConnect(FMLNetworkEvent.ClientConnectedToServerEvent event) { + NavigatorApi.layerManagers.forEach(LayerManager::clearFullCache); + } +} diff --git a/src/main/java/com/gtnewhorizons/navigator/api/model/layers/LayerManager.java b/src/main/java/com/gtnewhorizons/navigator/api/model/layers/LayerManager.java index 26ea84d..dae78b1 100644 --- a/src/main/java/com/gtnewhorizons/navigator/api/model/layers/LayerManager.java +++ b/src/main/java/com/gtnewhorizons/navigator/api/model/layers/LayerManager.java @@ -35,8 +35,9 @@ public abstract class LayerManager { private int miniMapHeight = 0; private int fullscreenMapWidth = 0; private int fullscreenMapHeight = 0; - private Integer currentDim = null; + private int currentDim; private SupportedMods openModGui; + private boolean refreshDim = true; private boolean clearFull, clearCurrent; public LayerManager(ButtonManager buttonManager) { @@ -201,7 +202,7 @@ private void recacheVisibleElements(int centerBlockX, int centerBlockZ) { if (clearFull) clearFull(); int dim = Minecraft.getMinecraft().thePlayer.dimension; - if (currentDim == null || currentDim != dim) { + if (refreshDim || currentDim != dim) { currentDim = dim; refreshDimCache(); } @@ -304,6 +305,7 @@ public boolean isEnabled(SupportedMods mod) { } protected void refreshDimCache() { + refreshDim = false; currentDimCache = dimCachedLocations.computeIfAbsent(currentDim, k -> new Long2ObjectOpenHashMap<>()); layerRenderer.values() .forEach(renderer -> renderer.setDimCache(currentDim)); @@ -320,6 +322,7 @@ public void clearFullCache() { } private void clearCurrent() { + clearCurrent = false; if (currentDimCache == null) return; currentDimCache.clear(); layerRenderer.values() @@ -327,7 +330,8 @@ private void clearCurrent() { } private void clearFull() { - currentDim = null; + clearFull = false; + refreshDim = true; dimCachedLocations.clear(); currentDimCache = null; layerRenderer.values()