Skip to content

Commit

Permalink
reset cache clear flags & clear cache when joining new world
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyfts committed Sep 5, 2024
1 parent d940235 commit bf18a8e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/gtnewhorizons/navigator/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,6 +19,9 @@ public void preInit(FMLPreInitializationEvent event) {
if (GeneralConfig.enableDebugLayers) {
NavigatorApi.registerLayerManager(DirtyChunkLayerManager.INSTANCE);
}
FMLCommonHandler.instance()
.bus()
.register(new EventHandler());
}

@Override
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/gtnewhorizons/navigator/EventHandler.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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));
Expand All @@ -320,14 +322,16 @@ public void clearFullCache() {
}

private void clearCurrent() {
clearCurrent = false;
if (currentDimCache == null) return;
currentDimCache.clear();
layerRenderer.values()
.forEach(LayerRenderer::clearCurrentCache);
}

private void clearFull() {
currentDim = null;
clearFull = false;
refreshDim = true;
dimCachedLocations.clear();
currentDimCache = null;
layerRenderer.values()
Expand Down

0 comments on commit bf18a8e

Please sign in to comment.