2020-05-06 09:48:49 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2019-05-18 05:01:44 +00:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Fri, 28 Sep 2018 21:49:53 -0400
|
|
|
|
Subject: [PATCH] Fix issues with entity loss due to unloaded chunks
|
|
|
|
|
|
|
|
Vanilla has risk of losing entities by causing them to be
|
|
|
|
removed from all chunks if they try to move into an unloaded chunk.
|
|
|
|
|
|
|
|
This pretty much means high chance this entity will be lost in this
|
|
|
|
scenario.
|
|
|
|
|
|
|
|
There is another case that adding an entity to the world can fail if
|
|
|
|
the chunk isn't loaded.
|
|
|
|
|
|
|
|
Lots of the server is designed around addEntity never expecting to fail
|
|
|
|
for these reasons, nor is it really logical.
|
|
|
|
|
|
|
|
This change ensures the chunks are always loaded when entities are
|
|
|
|
added to the world, or a valid entity moves between chunks.
|
|
|
|
|
2021-03-16 07:19:45 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/WorldServer.java b/src/main/java/net/minecraft/server/level/WorldServer.java
|
2021-04-07 05:17:32 +00:00
|
|
|
index b8a32742b2b2558a6155fc72e277a693c2306302..61d3524e962b97ed032af1990f8dc6513fbe51d6 100644
|
2021-03-16 07:19:45 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
|
2021-04-07 05:17:32 +00:00
|
|
|
@@ -854,11 +854,18 @@ public class WorldServer extends World implements GeneratorAccessSeed {
|
2020-06-25 14:09:55 +00:00
|
|
|
int k = MathHelper.floor(entity.locZ() / 16.0D);
|
2020-05-10 09:52:31 +00:00
|
|
|
|
2020-06-25 14:09:55 +00:00
|
|
|
if (!entity.inChunk || entity.chunkX != i || entity.chunkY != j || entity.chunkZ != k) {
|
|
|
|
+ // 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.inChunk && this.isChunkLoaded(entity.chunkX, entity.chunkZ)) {
|
|
|
|
this.getChunkAt(entity.chunkX, entity.chunkZ).a(entity, entity.chunkY);
|
|
|
|
}
|
2019-05-18 05:01:44 +00:00
|
|
|
|
2020-11-03 02:22:15 +00:00
|
|
|
- if (!entity.ck() && !this.isChunkLoaded(i, k)) {
|
|
|
|
+ if (!entity.valid && !entity.ck() && !this.isChunkLoaded(i, k)) { // Paper - always load chunks to register valid entities location
|
2020-06-25 14:09:55 +00:00
|
|
|
if (entity.inChunk) {
|
|
|
|
WorldServer.LOGGER.warn("Entity {} left loaded chunk area", entity);
|
|
|
|
}
|
2021-04-07 05:17:32 +00:00
|
|
|
@@ -1073,7 +1080,7 @@ public class WorldServer extends World implements GeneratorAccessSeed {
|
2019-05-18 05:01:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2019-12-12 16:20:43 +00:00
|
|
|
- IChunkAccess ichunkaccess = this.getChunkAt(MathHelper.floor(entity.locX() / 16.0D), MathHelper.floor(entity.locZ() / 16.0D), ChunkStatus.FULL, entity.attachedToPlayer);
|
|
|
|
+ IChunkAccess ichunkaccess = this.getChunkAt(MathHelper.floor(entity.locX() / 16.0D), MathHelper.floor(entity.locZ() / 16.0D), ChunkStatus.FULL, true); // Paper - always load chunks for entity adds
|
2019-05-18 05:01:44 +00:00
|
|
|
|
|
|
|
if (!(ichunkaccess instanceof Chunk)) {
|
|
|
|
return false;
|