2019-01-01 04:15:55 +01:00
From 668a1de336154c1375df2341f437b33e9f398e05 Mon Sep 17 00:00:00 2001
2018-07-24 04:55:27 +02:00
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
2019-01-01 04:15:55 +01:00
index 42b76b212..ca236a315 100644
2018-07-24 04:55:27 +02:00
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
2019-01-01 04:15:55 +01:00
@@ -714,8 +714,34 @@ public class Chunk implements IChunkAccess {
2018-12-17 06:18:06 +01:00
entity.chunkX = this.locX;
entity.chunkY = k;
entity.chunkZ = this.locZ;
2018-07-24 04:55:27 +02:00
- this.entitySlices[k].add(entity);
+
// Paper start
+ List<Entity> entitySlice = this.entitySlices[k];
+ boolean inThis = entitySlice.contains(entity);
2018-08-20 06:54:03 +02:00
+ List<Entity> currentSlice = entity.entitySlice;
+ if ((currentSlice != null && currentSlice.contains(entity)) || inThis) {
+ if (currentSlice == entitySlice || inThis) {
+ LogManager.getLogger().warn(entity + " was already in this chunk section! Report this to https://github.com/PaperMC/Paper/issues/1302");
2018-07-24 04:55:27 +02:00
+ new Throwable().printStackTrace();
+ return;
+ } else {
2018-08-20 06:54:03 +02:00
+ LogManager.getLogger().warn(entity + " is still in another ChunkSection! Report this to https://github.com/PaperMC/Paper/issues/1302");
2018-07-24 04:55:27 +02:00
+
+ Chunk chunk = entity.getCurrentChunk();
+ if (chunk != null) {
+ if (chunk != this) {
+ LogManager.getLogger().warn(entity + " was in another chunk at that! " + chunk.locX + "," + chunk.locZ);
+ }
+ chunk.removeEntity(entity);
+ } else {
+ removeEntity(entity);
+ }
+ new Throwable().printStackTrace();
+ }
+ }
+ entity.entitySlice = entitySlice;
+ entitySlice.add(entity);
+
this.markDirty();
2018-07-24 05:20:41 +02:00
if (entity instanceof EntityItem) {
itemCounts[k]++;
2019-01-01 04:15:55 +01:00
@@ -745,9 +771,13 @@ public class Chunk implements IChunkAccess {
2018-08-20 06:58:08 +02:00
i = this.entitySlices.length - 1;
2018-07-24 05:20:41 +02:00
}
2018-07-24 04:55:27 +02:00
// Paper start
2018-08-20 06:58:08 +02:00
- if (!this.entitySlices[i].remove(entity)) {
- return;
2018-08-21 02:20:40 +02:00
+ if (entity.entitySlice == null || !entity.entitySlice.contains(entity) || entitySlices[i] == entity.entitySlice) {
2018-07-24 04:55:27 +02:00
+ entity.entitySlice = null;
+ } else {
2018-08-20 06:54:03 +02:00
+ LogManager.getLogger().warn(entity + " was removed from a entitySlice we did not expect. Report this to https://github.com/PaperMC/Paper/issues/1302");
2018-07-24 04:55:27 +02:00
+ new Throwable().printStackTrace();
2018-08-20 06:58:08 +02:00
}
+ if (!this.entitySlices[i].remove(entity)) { return; }
2018-07-24 04:55:27 +02:00
this.markDirty();
2018-07-24 05:20:41 +02:00
if (entity instanceof EntityItem) {
itemCounts[i]--;
2019-01-01 04:15:55 +01:00
@@ -1028,6 +1058,7 @@ public class Chunk implements IChunkAccess {
2018-07-30 06:51:58 +02:00
}
// 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)
2018-07-24 04:55:27 +02:00
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
2019-01-01 04:15:55 +01:00
index 12ab5def2..50e616179 100644
2018-07-24 04:55:27 +02:00
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
2019-01-01 04:15:55 +01:00
@@ -62,6 +62,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
2018-07-24 04:55:27 +02:00
}
}
};
2018-08-20 06:54:03 +02:00
+ List<Entity> entitySlice = null;
2018-07-24 04:55:27 +02:00
// Paper end
static boolean isLevelAtLeast(NBTTagCompound tag, int level) {
return tag.hasKey("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
--
2019-01-01 04:15:55 +01:00
2.20.1
2018-07-24 04:55:27 +02:00