PaperMC/Spigot-Server-Patches/0303-Add-some-Debug-to-Chunk-Entity-slices.patch
Shane Freeder 3496f2d7e4
Updated Upstream (Bukkit/CraftBukkit/Spigot)
Developers!: You will need to clean up your work/Minecraft/1.13.2 folder for this

Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
b850a822 SPIGOT-4526: Add conversion time API for Zombie & subclasses

CraftBukkit Changes:
38cf676e SPIGOT-4534: CreatureSpawnEvent not being called for CHUNK_GEN
b446cb5d SPIGOT-4527: Fix sponges with waterlogged blocks
6ec8ea5c SPIGOT-4526: Add conversion time API for Zombie & subclasses
c64fe508 Mappings Update
a3c2ec03 Fix missing ServerListPingEvent call for legacy pings

Spigot Changes:
1dc156ce Rebuild patches
140f654d Mappings Update
2018-12-17 05:19:39 +00:00

89 lines
4 KiB
Diff

From 158100d122f5fd7e1c280aed126c53675bcc0a3a 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 f7990fbdb..4f01140e7 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -715,8 +715,34 @@ public class Chunk implements IChunkAccess {
entity.chunkX = this.locX;
entity.chunkY = k;
entity.chunkZ = this.locZ;
- this.entitySlices[k].add(entity);
+
// Paper start
+ List<Entity> entitySlice = this.entitySlices[k];
+ boolean inThis = entitySlice.contains(entity);
+ 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");
+ new Throwable().printStackTrace();
+ return;
+ } else {
+ LogManager.getLogger().warn(entity + " is still in another ChunkSection! Report this to https://github.com/PaperMC/Paper/issues/1302");
+
+ 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();
if (entity instanceof EntityItem) {
itemCounts[k]++;
@@ -746,9 +772,13 @@ public class Chunk implements IChunkAccess {
i = this.entitySlices.length - 1;
}
// Paper start
- if (!this.entitySlices[i].remove(entity)) {
- return;
+ if (entity.entitySlice == null || !entity.entitySlice.contains(entity) || 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/1302");
+ new Throwable().printStackTrace();
}
+ if (!this.entitySlices[i].remove(entity)) { return; }
this.markDirty();
if (entity instanceof EntityItem) {
itemCounts[i]--;
@@ -1029,6 +1059,7 @@ public class Chunk implements IChunkAccess {
}
// 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 fe0590dea..469dce5df 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -64,6 +64,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
}
}
};
+ List<Entity> entitySlice = null;
// Paper end
static boolean isLevelAtLeast(NBTTagCompound tag, int level) {
return tag.hasKey("Bukkit.updateLevel") && tag.getInt("Bukkit.updateLevel") >= level;
--
2.20.0