Skip to content

Commit

Permalink
Ensure ChunkLoaderHandler gets un-loaded when the world does.
Browse files Browse the repository at this point in the history
  • Loading branch information
covers1624 committed Sep 22, 2024
1 parent 004f0bf commit 27210f9
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static void init(IEventBus modBus) {
NeoForge.EVENT_BUS.addListener(ChunkLoaderHandler::onPlayerLogin);
NeoForge.EVENT_BUS.addListener(ChunkLoaderHandler::onPlayerLoggedOut);
NeoForge.EVENT_BUS.addListener(ChunkLoaderHandler::onWorldLoad);
NeoForge.EVENT_BUS.addListener(ChunkLoaderHandler::onWorldUnload);
NeoForge.EVENT_BUS.addListener(ChunkLoaderHandler::onWorldTick);
}

Expand Down Expand Up @@ -104,6 +105,14 @@ private static void onWorldLoad(LevelEvent.Load event) {
getInstance().onOverWorldLoad();
}

private static void onWorldUnload(LevelEvent.Unload event) {
if (!(event.getLevel() instanceof ServerLevel level)) return;

if (!level.dimension().equals(Level.OVERWORLD)) return;

instance = null;
}

private static void onWorldTick(TickEvent.LevelTickEvent event) {
if (event.level instanceof ServerLevel world) {
if (world.dimension() == Level.OVERWORLD) {
Expand Down

0 comments on commit 27210f9

Please sign in to comment.