From a766603b380ff339781b434877ee667464739868 Mon Sep 17 00:00:00 2001 From: LexManos Date: Wed, 27 Feb 2013 00:57:35 -0800 Subject: [PATCH] Merge commit '695b080197bd577cc34fe6dbc72b74f4a74b2d5c' into snapshot15 Testing cherry picking. --- .../common/DimensionManager.java | 22 +++++++++++++++---- .../common/ForgeChunkManager.java | 17 +++++++++++++- .../net/minecraft/entity/Entity.java.patch | 10 ++++++++- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/common/net/minecraftforge/common/DimensionManager.java b/common/net/minecraftforge/common/DimensionManager.java index 918525f98..8cf50502d 100644 --- a/common/net/minecraftforge/common/DimensionManager.java +++ b/common/net/minecraftforge/common/DimensionManager.java @@ -240,14 +240,28 @@ public class DimensionManager */ public static void unloadWorlds(Hashtable worldTickTimes) { for (int id : unloadQueue) { + WorldServer w = worlds.get(id); try { - worlds.get(id).saveAllChunks(true, null); + if (w != null) + { + w.saveAllChunks(true, null); + } + else + { + FMLLog.warning("Unexpected world unload - world %d is already unloaded", id); + } } catch (MinecraftException e) { e.printStackTrace(); } - MinecraftForge.EVENT_BUS.post(new WorldEvent.Unload(worlds.get(id))); - ((WorldServer)worlds.get(id)).flush(); - setWorld(id, null); + finally + { + if (w != null) + { + MinecraftForge.EVENT_BUS.post(new WorldEvent.Unload(w)); + w.flush(); + setWorld(id, null); + } + } } unloadQueue.clear(); } diff --git a/common/net/minecraftforge/common/ForgeChunkManager.java b/common/net/minecraftforge/common/ForgeChunkManager.java index 5145c2c18..4794f53b2 100644 --- a/common/net/minecraftforge/common/ForgeChunkManager.java +++ b/common/net/minecraftforge/common/ForgeChunkManager.java @@ -880,7 +880,22 @@ public class ForgeChunkManager public static Chunk fetchDormantChunk(long coords, World world) { Cache cache = dormantChunkCache.get(world); - return cache == null ? null : cache.getIfPresent(coords); + if (cache == null) + { + return null; + } + Chunk chunk = cache.getIfPresent(coords); + if (chunk != null) + { + for (List eList : chunk.entityLists) + { + for (Entity e: eList) + { + e.resetEntityId(); + } + } + } + return chunk; } static void captureConfig(File configDir) diff --git a/patches/minecraft/net/minecraft/entity/Entity.java.patch b/patches/minecraft/net/minecraft/entity/Entity.java.patch index cf5412c69..6cdfb7579 100644 --- a/patches/minecraft/net/minecraft/entity/Entity.java.patch +++ b/patches/minecraft/net/minecraft/entity/Entity.java.patch @@ -138,7 +138,7 @@ } public int func_82143_as() -@@ -2399,4 +2441,84 @@ +@@ -2399,4 +2441,92 @@ { return this.isBurning(); } @@ -221,5 +221,13 @@ + { + persistentID = UUID.randomUUID(); + } ++ } ++ ++ /** ++ * Reset the entity ID to a new value. Not to be used from Mod code ++ */ ++ public final void resetEntityId() ++ { ++ this.entityId = nextEntityID++; + } }