mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-03 01:10:37 +01:00
17dca0a0fe
After witnessing behavior of the regeneration logs, its clear that Vanilla has had bugs with saving duplicate entities for a while.... Some entities are saved in multiple chunks, and now we are bringing those duplicates out that use to never surface. This mode will analyze if the entity appears to be a duplicate (near the other dupe uuid) and delete the entity instead. This should reduce regenerations to entities that are nowhere near each other, and therefore more likely to be subject to real UUID collisions due to our previous bug, and therefor should survive the chunk load.
86 lines
3.7 KiB
Diff
86 lines
3.7 KiB
Diff
From 099d9012a80cc417b8b3be962d67942ce3162b0c 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 ccb30d5bfd..94b294e87b 100644
|
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
|
@@ -681,8 +681,33 @@ public class Chunk {
|
|
entity.ab = this.locX;
|
|
entity.ac = k;
|
|
entity.ad = this.locZ;
|
|
- 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();
|
|
entity.setCurrentChunk(this);
|
|
entityCounts.increment(entity.getMinecraftKeyString());
|
|
@@ -726,6 +751,12 @@ public class Chunk {
|
|
|
|
// Paper start
|
|
if (!this.entitySlices[i].remove(entity)) { return; }
|
|
+ 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();
|
|
entity.setCurrentChunk(null);
|
|
entityCounts.decrement(entity.getMinecraftKeyString());
|
|
@@ -954,6 +985,7 @@ public class Chunk {
|
|
}
|
|
// 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 eb8904a728..1e64d5fcd6 100644
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
|
@@ -59,6 +59,7 @@ public abstract class Entity implements ICommandListener, KeyedObject { // Paper
|
|
}
|
|
}
|
|
};
|
|
+ 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
|
|
|