Paper/Spigot-Server-Patches/0302-Add-some-Debug-to-Chunk-Entity-slices.patch
Aikar 7ab257e4f1
Remove ChunkSection debug - #1302
While these logs indicate something is 'off', we've had no reports
of visible 'issues' with entities, and no one is going to take the
time to debug this farther, so just getting rid of the logs so it's
like its never happening!

Ignorance is bliss.
2019-02-23 12:24:23 -05:00

80 lines
3.2 KiB
Diff

From abf1bf94c272bcaf8daf2d6e5252e54a426bf936 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 23 Jul 2018 22:44:23 -0400
Subject: [PATCH] Add some Debug to Chunk Entity slices
If we detect unexpected state, log and try to recover
This should hopefully avoid duplicate entities ever being created
if the entity was to end up in 2 different chunk slices
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index 42b76b2122..1c9e2cb1ce 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -714,8 +714,27 @@ public class Chunk implements IChunkAccess {
entity.chunkX = this.locX;
entity.chunkY = k;
entity.chunkZ = this.locZ;
- this.entitySlices[k].add(entity);
+
// Paper start
+ List<Entity> entitySlice = this.entitySlices[k];
+ boolean inThis = entitySlice.contains(entity);
+ List<Entity> currentSlice = entity.entitySlice;
+ if ((currentSlice != null && currentSlice.contains(entity)) || inThis) {
+ if (currentSlice == entitySlice || inThis) {
+ return;
+ } else {
+ Chunk chunk = entity.getCurrentChunk();
+ if (chunk != null) {
+ chunk.removeEntity(entity);
+ } else {
+ removeEntity(entity);
+ }
+ new Throwable().printStackTrace();
+ }
+ }
+ entity.entitySlice = entitySlice;
+ entitySlice.add(entity);
+
this.markDirty();
if (entity instanceof EntityItem) {
itemCounts[k]++;
@@ -745,9 +764,10 @@ public class Chunk implements IChunkAccess {
i = this.entitySlices.length - 1;
}
// Paper start
- if (!this.entitySlices[i].remove(entity)) {
- return;
+ if (entity.entitySlice == null || !entity.entitySlice.contains(entity) || entitySlices[i] == entity.entitySlice) {
+ entity.entitySlice = null;
}
+ if (!this.entitySlices[i].remove(entity)) { return; }
this.markDirty();
if (entity instanceof EntityItem) {
itemCounts[i]--;
@@ -1028,6 +1048,7 @@ public class Chunk implements IChunkAccess {
}
// Spigot End
entity.setCurrentChunk(null); // Paper
+ entity.entitySlice = null; // Paper
// Do not pass along players, as doing so can get them stuck outside of time.
// (which for example disables inventory icon updates and prevents block breaking)
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 61a547a40d..15a81d1eb9 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -62,6 +62,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
}
}
};
+ List<Entity> entitySlice = null;
// Paper end
static boolean isLevelAtLeast(NBTTagCompound tag, int level) {
return tag.hasKey("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
--
2.20.1