From ea976ebb2f86efe323a9f32627569f8154532512 Mon Sep 17 00:00:00 2001 From: Nedelosk Date: Sat, 24 Dec 2016 03:14:14 +0100 Subject: [PATCH] Remove unloaded climate regions --- src/main/java/forestry/api/climate/IClimateManager.java | 2 ++ .../java/forestry/core/climate/ClimateEventHandler.java | 8 ++++++++ src/main/java/forestry/core/climate/ClimateManager.java | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/src/main/java/forestry/api/climate/IClimateManager.java b/src/main/java/forestry/api/climate/IClimateManager.java index 59e9873d8..f4ec133c2 100644 --- a/src/main/java/forestry/api/climate/IClimateManager.java +++ b/src/main/java/forestry/api/climate/IClimateManager.java @@ -28,6 +28,8 @@ public interface IClimateManager { void removeSource(IClimateSourceProvider source); + void onWorldUnload(World world); + @Nullable IClimatePosition getPosition(World world, BlockPos pos); diff --git a/src/main/java/forestry/core/climate/ClimateEventHandler.java b/src/main/java/forestry/core/climate/ClimateEventHandler.java index cbe652b37..0a915b018 100644 --- a/src/main/java/forestry/core/climate/ClimateEventHandler.java +++ b/src/main/java/forestry/core/climate/ClimateEventHandler.java @@ -16,8 +16,11 @@ import java.util.Map; import forestry.api.climate.IClimateRegion; import forestry.api.core.ForestryAPI; +import forestry.core.multiblock.MultiblockRegistry; import net.minecraft.server.MinecraftServer; import net.minecraft.world.World; +import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; @@ -148,6 +151,11 @@ public class ClimateEventHandler { } }*/ + + @SubscribeEvent() + public void onWorldUnload(WorldEvent.Unload unloadWorldEvent) { + ForestryAPI.climateManager.onWorldUnload(unloadWorldEvent.getWorld()); + } @SubscribeEvent public void onWorldTick(TickEvent.WorldTickEvent event) { diff --git a/src/main/java/forestry/core/climate/ClimateManager.java b/src/main/java/forestry/core/climate/ClimateManager.java index d23cf5d6f..6851a0b5c 100644 --- a/src/main/java/forestry/core/climate/ClimateManager.java +++ b/src/main/java/forestry/core/climate/ClimateManager.java @@ -152,6 +152,11 @@ public class ClimateManager implements IClimateManager { } return null; } + + @Override + public void onWorldUnload(World world) { + regions.remove(world); + } @Override public IClimateProvider getDefaultClimate(World world, BlockPos pos) {