2020-05-06 09:48:49 +00:00
|
|
|
From 0000000000000000000000000000000000000000 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
|
2020-06-25 14:09:55 +00:00
|
|
|
index a27f91e6c3d1f5dd0adf8a3b48a640cc63676114..3ba19f75d24a1539c94f4fed9b8f90aecc918cdc 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
|
2020-06-25 14:09:55 +00:00
|
|
|
@@ -510,6 +510,25 @@ public class Chunk implements IChunkAccess {
|
2019-04-06 03:08:45 +00:00
|
|
|
if (k >= this.entitySlices.length) {
|
|
|
|
k = this.entitySlices.length - 1;
|
|
|
|
}
|
|
|
|
+ // Paper - remove from any old list if its in one
|
|
|
|
+ List<Entity> nextSlice = this.entitySlices[k]; // the next list to be added to
|
2018-08-20 04:54:03 +00:00
|
|
|
+ List<Entity> currentSlice = entity.entitySlice;
|
2019-04-06 03:08:45 +00:00
|
|
|
+ if (nextSlice == currentSlice) {
|
|
|
|
+ if (World.DEBUG_ENTITIES) MinecraftServer.LOGGER.warn("Entity was already in this chunk!" + entity, new Throwable());
|
|
|
|
+ return; // ??? silly plugins
|
|
|
|
+ }
|
|
|
|
+ if (currentSlice != null && currentSlice.contains(entity)) {
|
|
|
|
+ // Still in an old chunk...
|
|
|
|
+ if (World.DEBUG_ENTITIES) MinecraftServer.LOGGER.warn("Entity is still in another chunk!" + entity, new Throwable());
|
|
|
|
+ Chunk chunk = entity.getCurrentChunk();
|
|
|
|
+ if (chunk != null) {
|
|
|
|
+ chunk.removeEntity(entity);
|
2018-07-24 02:55:27 +00:00
|
|
|
+ } else {
|
2019-04-06 03:08:45 +00:00
|
|
|
+ removeEntity(entity);
|
2018-07-24 02:55:27 +00:00
|
|
|
+ }
|
2019-04-06 03:08:45 +00:00
|
|
|
+ currentSlice.remove(entity); // Just incase the above did not remove from the previous slice
|
2018-07-24 02:55:27 +00:00
|
|
|
+ }
|
2019-04-06 03:08:45 +00:00
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
if (!entity.inChunk || entity.getCurrentChunk() != this) entityCounts.increment(entity.getMinecraftKeyString()); // Paper
|
|
|
|
entity.inChunk = true;
|
2020-06-25 14:09:55 +00:00
|
|
|
@@ -519,6 +538,7 @@ public class Chunk implements IChunkAccess {
|
2019-04-30 22:51:03 +00:00
|
|
|
entity.chunkZ = this.loc.z;
|
2020-01-28 00:16:53 +00:00
|
|
|
this.entities.add(entity); // Paper - per chunk entity list
|
2019-04-06 03:08:45 +00:00
|
|
|
this.entitySlices[k].add(entity);
|
|
|
|
+ entity.entitySlice = this.entitySlices[k]; // Paper
|
2019-04-30 22:51:03 +00:00
|
|
|
this.markDirty(); // Paper
|
|
|
|
}
|
|
|
|
|
2020-06-25 14:09:55 +00:00
|
|
|
@@ -543,6 +563,10 @@ public class Chunk implements IChunkAccess {
|
2020-01-31 16:09:56 +00:00
|
|
|
|
2018-07-24 02:55:27 +00:00
|
|
|
// Paper start
|
2019-04-06 03:08:45 +00:00
|
|
|
if (entity.currentChunk != null && entity.currentChunk.get() == this) entity.setCurrentChunk(null);
|
|
|
|
+ if (entitySlices[i] == entity.entitySlice) {
|
2018-07-24 02:55:27 +00:00
|
|
|
+ entity.entitySlice = null;
|
2020-04-05 01:09:27 +00:00
|
|
|
+ entity.inChunk = false;
|
2019-04-06 03:08:45 +00:00
|
|
|
+ }
|
|
|
|
if (!this.entitySlices[i].remove(entity)) {
|
|
|
|
return;
|
2018-08-20 04:58:08 +00:00
|
|
|
}
|
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
|
2020-06-30 05:20:29 +00:00
|
|
|
index af6f0c391e6e410f0bf4e4e6ddf6fd18bb4d26ed..b0338278f3cfecdb30e1d2febf1ff2a04d0cc66d 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
|
2020-06-26 01:58:00 +00:00
|
|
|
@@ -71,6 +71,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
|
2019-12-12 00:03:31 +00:00
|
|
|
|
|
|
|
public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper
|