Paper/patches/server/0237-Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch
Jake Potrebic cfe3ad1b0f
Updated Upstream (Bukkit/CraftBukkit/Spigot)
Upstream has released updates that appear 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:
45d9c73c SPIGOT-7043: EnderChest does not implement Lidded
86b95f34 SPIGOT-7047: Add Player#getLastDeathLocation

CraftBukkit Changes:
b2557f6ac SPIGOT-7041: Custom BiomeProvider not used when world set to type FLAT
732c50cab SPIGOT-7043: EnderChest does not implement Lidded
6209029ea SPIGOT-7048: addPassenger() not working when vehicle is player
3aa7836df SPIGOT-7047: Add Player#getLastDeathLocation
7d522cd26 SPIGOT-7050: Enchantment data of items will not be saved correctly when saved in YAML configuration file

Spigot Changes:
1dffefb4 Rebuild patches
2022-06-09 18:20:55 -07:00

130 lines
7.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 21 Jul 2018 08:25:40 -0400
Subject: [PATCH] Add Debug Entities option to debug dupe uuid issues
Add -Ddebug.entities=true to your JVM flags to gain more information
1.17: Needs to be reworked for new entity storage system
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
index f9ef45635b731cafc9b6879603cac34c146833b0..29482bebf5b878c698283720d1452ef237da5516 100644
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
@@ -1389,6 +1389,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
} else {
ChunkMap.TrackedEntity playerchunkmap_entitytracker = new ChunkMap.TrackedEntity(entity, i, j, entitytypes.trackDeltas());
+ entity.tracker = playerchunkmap_entitytracker; // Paper - Fast access to tracker
this.entityMap.put(entity.getId(), playerchunkmap_entitytracker);
playerchunkmap_entitytracker.updatePlayers(this.level.players());
if (entity instanceof ServerPlayer) {
@@ -1431,7 +1432,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
if (playerchunkmap_entitytracker1 != null) {
playerchunkmap_entitytracker1.broadcastRemoved();
}
-
+ entity.tracker = null; // Paper - We're no longer tracked
}
protected void tick() {
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 1e559d238441d28c52b3305c42dec0f6115b2626..547aea9a2ead3eff5690f18cfc351b01dd4cd395 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -215,6 +215,9 @@ public class ServerLevel extends Level implements WorldGenLevel {
public final LevelStorageSource.LevelStorageAccess convertable;
public final UUID uuid;
public boolean hasPhysicsEvent = true; // Paper
+ public static Throwable getAddToWorldStackTrace(Entity entity) {
+ return new Throwable(entity + " Added to world at " + new java.util.Date());
+ }
@Override public LevelChunk getChunkIfLoaded(int x, int z) { // Paper - this was added in world too but keeping here for NMS ABI
return this.chunkSource.getChunk(x, z, false);
@@ -1120,7 +1123,28 @@ public class ServerLevel extends Level implements WorldGenLevel {
// CraftBukkit start
private boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
org.spigotmc.AsyncCatcher.catchOp("entity add"); // Spigot
+ // Paper start
+ if (entity.valid) {
+ MinecraftServer.LOGGER.error("Attempted Double World add on " + entity, new Throwable());
+
+ if (DEBUG_ENTITIES) {
+ Throwable thr = entity.addedToWorldStack;
+ if (thr == null) {
+ MinecraftServer.LOGGER.error("Double add entity has no add stacktrace");
+ } else {
+ MinecraftServer.LOGGER.error("Double add stacktrace: ", thr);
+ }
+ }
+ return true;
+ }
+ // Paper end
if (entity.isRemoved()) {
+ // Paper start
+ if (DEBUG_ENTITIES) {
+ new Throwable("Tried to add entity " + entity + " but it was marked as removed already").printStackTrace(); // CraftBukkit
+ getAddToWorldStackTrace(entity).printStackTrace();
+ }
+ // Paper end
// WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getKey(entity.getType())); // CraftBukkit
return false;
} else {
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 57b1d37bfe35215552c138caad8597986f755064..d020cbe64e13b479e22a8f6c090165390663af63 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -229,6 +229,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper
private CraftEntity bukkitEntity;
+ public @org.jetbrains.annotations.Nullable net.minecraft.server.level.ChunkMap.TrackedEntity tracker; // Paper
+ public @Nullable Throwable addedToWorldStack; // Paper - entity debug
public CraftEntity getBukkitEntity() {
if (this.bukkitEntity == null) {
this.bukkitEntity = CraftEntity.getEntity(this.level.getCraftServer(), this);
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index 13fcd9d885043444d3a2c5a3d9bd1c906b4c4934..2225921e988cdcaa4fb906b281c237972c6e7c1b 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -148,6 +148,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
public boolean pvpMode;
public boolean keepSpawnInMemory = true;
public org.bukkit.generator.ChunkGenerator generator;
+ public static final boolean DEBUG_ENTITIES = Boolean.getBoolean("debug.entities"); // Paper
public boolean preventPoiUpdated = false; // CraftBukkit - SPIGOT-5710
public boolean captureBlockStates = false;
diff --git a/src/main/java/net/minecraft/world/level/entity/EntityLookup.java b/src/main/java/net/minecraft/world/level/entity/EntityLookup.java
index e6b9f812e521abd552e0c7dc0429d5a62f2bfc35..f4731d69946871768ecf16149a47d2ef1cb3e910 100644
--- a/src/main/java/net/minecraft/world/level/entity/EntityLookup.java
+++ b/src/main/java/net/minecraft/world/level/entity/EntityLookup.java
@@ -34,6 +34,26 @@ public class EntityLookup<T extends EntityAccess> {
UUID uUID = entity.getUUID();
if (this.byUuid.containsKey(uUID)) {
LOGGER.warn("Duplicate entity UUID {}: {}", uUID, entity);
+ // Paper start - extra debug info
+ if (entity instanceof net.minecraft.world.entity.Entity entityCast) {
+ if (net.minecraft.server.level.ServerLevel.DEBUG_ENTITIES) {
+ entityCast.addedToWorldStack = net.minecraft.server.level.ServerLevel.getAddToWorldStackTrace(entityCast);
+ }
+
+ T old = this.byUuid.get(entity.getUUID());
+ if (old instanceof net.minecraft.world.entity.Entity oldCast && old != null && oldCast.getId() != entity.getId() && oldCast.valid) {
+ LOGGER.error("Overwrote an existing entity " + oldCast + " with " + entity);
+ if (net.minecraft.server.level.ServerLevel.DEBUG_ENTITIES) {
+ if (oldCast.addedToWorldStack != null) {
+ oldCast.addedToWorldStack.printStackTrace();
+ } else {
+ LOGGER.error("Oddly, the old entity was not added to the world in the normal way. Plugins?");
+ }
+ entityCast.addedToWorldStack.printStackTrace();
+ }
+ }
+ }
+ // Paper end
} else {
this.byUuid.put(uUID, entity);
this.byId.put(entity.getId(), entity);