2019-03-20 01:46:00 +00:00
|
|
|
From 96241e585235ed412e893f10f2cc1a9df400f679 Mon Sep 17 00:00:00 2001
|
2018-07-24 02:55:27 +00: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-03-20 01:46:00 +00:00
|
|
|
index 42b76b212..7dd59ee03 100644
|
2018-07-24 02:55:27 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
2019-02-23 17:24:23 +00:00
|
|
|
@@ -714,8 +714,27 @@ public class Chunk implements IChunkAccess {
|
2018-12-17 05:18:06 +00:00
|
|
|
entity.chunkX = this.locX;
|
|
|
|
entity.chunkY = k;
|
|
|
|
entity.chunkZ = this.locZ;
|
2018-07-24 02:55:27 +00:00
|
|
|
- this.entitySlices[k].add(entity);
|
|
|
|
+
|
|
|
|
// Paper start
|
|
|
|
+ List<Entity> entitySlice = this.entitySlices[k];
|
|
|
|
+ boolean inThis = entitySlice.contains(entity);
|
2018-08-20 04:54:03 +00:00
|
|
|
+ List<Entity> currentSlice = entity.entitySlice;
|
2019-03-02 23:52:16 +00:00
|
|
|
+ if (inThis || (currentSlice != null && currentSlice.contains(entity))) {
|
2018-08-20 04:54:03 +00:00
|
|
|
+ if (currentSlice == entitySlice || inThis) {
|
2018-07-24 02:55:27 +00:00
|
|
|
+ return;
|
|
|
|
+ } else {
|
|
|
|
+ Chunk chunk = entity.getCurrentChunk();
|
|
|
|
+ if (chunk != null) {
|
|
|
|
+ chunk.removeEntity(entity);
|
|
|
|
+ } else {
|
|
|
|
+ removeEntity(entity);
|
|
|
|
+ }
|
2019-03-02 23:52:16 +00:00
|
|
|
+ currentSlice.remove(entity); // Just incase the above did not remove from this target slice
|
2018-07-24 02:55:27 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ entity.entitySlice = entitySlice;
|
|
|
|
+ entitySlice.add(entity);
|
|
|
|
+
|
|
|
|
this.markDirty();
|
2018-07-24 03:20:41 +00:00
|
|
|
if (entity instanceof EntityItem) {
|
|
|
|
itemCounts[k]++;
|
2019-02-23 17:24:23 +00:00
|
|
|
@@ -745,9 +764,10 @@ public class Chunk implements IChunkAccess {
|
2018-08-20 04:58:08 +00:00
|
|
|
i = this.entitySlices.length - 1;
|
2018-07-24 03:20:41 +00:00
|
|
|
}
|
2018-07-24 02:55:27 +00:00
|
|
|
// Paper start
|
2018-08-20 04:58:08 +00:00
|
|
|
- if (!this.entitySlices[i].remove(entity)) {
|
|
|
|
- return;
|
2018-08-21 00:20:40 +00:00
|
|
|
+ if (entity.entitySlice == null || !entity.entitySlice.contains(entity) || entitySlices[i] == entity.entitySlice) {
|
2018-07-24 02:55:27 +00:00
|
|
|
+ entity.entitySlice = null;
|
2018-08-20 04:58:08 +00:00
|
|
|
}
|
|
|
|
+ if (!this.entitySlices[i].remove(entity)) { return; }
|
2018-07-24 02:55:27 +00:00
|
|
|
this.markDirty();
|
2018-07-24 03:20:41 +00:00
|
|
|
if (entity instanceof EntityItem) {
|
|
|
|
itemCounts[i]--;
|
2019-02-23 17:24:23 +00:00
|
|
|
@@ -1028,6 +1048,7 @@ public class Chunk implements IChunkAccess {
|
2018-07-30 04:51:58 +00: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 02:55:27 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
2019-03-20 01:46:00 +00:00
|
|
|
index a211cb945..72e43622e 100644
|
2018-07-24 02:55:27 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
2019-01-01 03:15:55 +00:00
|
|
|
@@ -62,6 +62,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
2018-07-24 02:55:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2018-08-20 04:54:03 +00:00
|
|
|
+ List<Entity> entitySlice = null;
|
2018-07-24 02:55:27 +00:00
|
|
|
// Paper end
|
|
|
|
static boolean isLevelAtLeast(NBTTagCompound tag, int level) {
|
|
|
|
return tag.hasKey("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
|
|
|
|
--
|
2019-03-20 01:46:00 +00:00
|
|
|
2.21.0
|
2018-07-24 02:55:27 +00:00
|
|
|
|