2018-07-24 05:20:41 +02:00
From 1a1fa5156619969d65be7638a7cd2f056c9a933c 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
2018-07-24 05:20:41 +02:00
index aa75cc420..56a74c606 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
2018-07-24 05:20:41 +02:00
@@ -712,8 +712,33 @@ public class Chunk implements IChunkAccess {
entity.ae = this.locX;
entity.af = k;
entity.ag = 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);
+ if (entity.entitySlice != null || inThis) {
+ if (entity.entitySlice == entitySlice || inThis) {
+ LogManager.getLogger().warn(entity + " was already in this chunk section! Report this to https://github.com/PaperMC/Paper/issues/1223");
+ new Throwable().printStackTrace();
+ return;
+ } else {
+ LogManager.getLogger().warn(entity + " is still in another ChunkSection! Report this to https://github.com/PaperMC/Paper/issues/1223");
+
+ 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]++;
@@ -746,6 +771,12 @@ public class Chunk implements IChunkAccess {
if (!this.entitySlices[i].remove(entity)) {
return;
}
2018-07-24 04:55:27 +02:00
+ if (entitySlices[i] == entity.entitySlice) {
+ entity.entitySlice = null;
+ } else {
+ LogManager.getLogger().warn(entity + " was removed from a entitySlice we did not expect. Report this to https://github.com/PaperMC/Paper/issues/1223");
+ new Throwable().printStackTrace();
+ }
this.markDirty();
2018-07-24 05:20:41 +02:00
if (entity instanceof EntityItem) {
itemCounts[i]--;
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
2018-07-24 05:20:41 +02:00
index b6d6d4f37..bc4ba9f3c 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
2018-07-24 05:20:41 +02:00
@@ -63,6 +63,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
2018-07-24 04:55:27 +02:00
}
}
};
+ Object entitySlice = null;
// Paper end
static boolean isLevelAtLeast(NBTTagCompound tag, int level) {
return tag.hasKey("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
--
2.18.0