aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0383-Fix-issues-with-entity-loss-due-to-unloaded-chunks.patch
blob: 4be009cd56f76f3610c1e942d5ac58038eb25ab3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
From fe0d3a1329061e1007cac3067f00b4a3066cb1e2 Mon Sep 17 00:00:00 2001
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.

diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
index 192b3be1f0..82c3bc60d0 100644
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
@@ -640,7 +640,7 @@ public class WorldServer extends World {
                 this.getChunkAt(entity.chunkX, entity.chunkZ).a(entity, entity.chunkY);
             }
 
-            if (!entity.bU() && !this.isChunkLoaded(i, k)) {
+            if (!entity.valid && !entity.bU() && !this.isChunkLoaded(i, k)) { // Paper - always load chunks to register valid entities location
                 entity.inChunk = false;
             } else {
                 this.getChunkAt(i, k).a(entity);
@@ -975,7 +975,7 @@ public class WorldServer extends World {
                 return false;
             }
             // CraftBukkit end
-            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
 
             if (!(ichunkaccess instanceof Chunk)) {
                 return false;
-- 
2.22.1