From ba6c2748426b468c9004b3e19e7d89f783d9800b Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 30 Jan 2021 16:50:02 +0100 Subject: [PATCH] remove unloaded aura chunks --- .../ellpeck/naturesaura/events/CommonEvents.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java b/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java index 884388ee..2c31542b 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/CommonEvents.java @@ -21,6 +21,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.IChunk; import net.minecraft.world.gen.GenerationStage.Decoration; import net.minecraft.world.server.ChunkHolder; import net.minecraft.world.server.ChunkManager; @@ -29,6 +30,7 @@ import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.event.world.BiomeLoadingEvent; +import net.minecraftforge.event.world.ChunkEvent; import net.minecraftforge.event.world.ChunkWatchEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.ObfuscationReflectionHelper; @@ -74,6 +76,19 @@ public class CommonEvents { event.addCapability(new ResourceLocation(NaturesAura.MOD_ID, "data"), new WorldData()); } + @SubscribeEvent + public void onChunkUnload(ChunkEvent.Unload event) { + IChunk iChunk = event.getChunk(); + if (iChunk instanceof Chunk) { + Chunk chunk = (Chunk) iChunk; + IAuraChunk auraChunk = chunk.getCapability(NaturesAuraAPI.capAuraChunk).orElse(null); + if (auraChunk instanceof AuraChunk) { + WorldData data = (WorldData) IWorldData.getWorldData(chunk.getWorld()); + data.auraChunksWithSpots.remove(chunk.getPos().asLong()); + } + } + } + @SubscribeEvent public void onItemUse(PlayerInteractEvent.RightClickBlock event) { PlayerEntity player = event.getPlayer();