From b74f95d9f96517b9ad987302addfcb3c6bc69518 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sun, 10 May 2020 05:52:31 -0400 Subject: [PATCH] Properly remove Entities from current chunk We store a reference to the chunk the entity is currently in, so use it to more accurately unregister it in chunkCheck Should maybe fix some entity loss issues. --- ...sues-with-entity-loss-due-to-unloaded-chunks.patch | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Spigot-Server-Patches/Fix-issues-with-entity-loss-due-to-unloaded-chunks.patch b/Spigot-Server-Patches/Fix-issues-with-entity-loss-due-to-unloaded-chunks.patch index ce731fd876..35b7e708a5 100644 --- a/Spigot-Server-Patches/Fix-issues-with-entity-loss-due-to-unloaded-chunks.patch +++ b/Spigot-Server-Patches/Fix-issues-with-entity-loss-due-to-unloaded-chunks.patch @@ -23,8 +23,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -0,0 +0,0 @@ public class WorldServer extends World { - this.getChunkAt(entity.chunkX, entity.chunkZ).a(entity, entity.chunkY); + int k = MathHelper.floor(entity.locZ() / 16.0D); + + if (!entity.inChunk || entity.chunkX != i || entity.chunkY != j || entity.chunkZ != k) { +- if (entity.inChunk && this.isChunkLoaded(entity.chunkX, entity.chunkZ)) { +- this.getChunkAt(entity.chunkX, entity.chunkZ).a(entity, entity.chunkY); ++ // Paper start - remove entity if its in a chunk more correctly. ++ Chunk currentChunk = entity.getCurrentChunk(); ++ if (currentChunk != null) { ++ currentChunk.removeEntity(entity); } ++ // Paper end - if (!entity.cc() && !this.isChunkLoaded(i, k)) { + if (!entity.valid && !entity.cc() && !this.isChunkLoaded(i, k)) { // Paper - always load chunks to register valid entities location