Paper/patches/server/0233-Add-Debug-Entities-option-to-debug-dupe-uuid-issues.patch

130 lines
7.5 KiB
Diff
Raw Normal View History

2021-06-14 08:41:01 +02:00
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
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: cc9aa21a SPIGOT-6399, SPIGOT-7344: Clarify collidable behavior for player entities f23325b6 Add API for per-world simulation distances 26e1774e Add API for per-world view distances 0b541e60 Add PlayerLoginEvent#getRealAddress 5f027d2d PR-949: Add Vector#fromJOML() overloads for read-only vector types CraftBukkit Changes: bcf56171a PR-1321: Clean up some stuff which got missed during previous PRs 7f833a2d1 SPIGOT-7462: Players no longer drop XP after dying near a Sculk Catalyst 752aac669 Implement APIs for per world view and simulation distances 57d7ef433 Preserve empty enchantment tags for glow effect 465ec3fb4 Remove connected check on setScoreboard f90ce621e Use one PermissibleBase for all command blocks 5876cca44 SPIGOT-7550: Fix creation of Arrow instances f03fc3aa3 SPIGOT-7549: ServerTickManager#setTickRate incorrect Precondition 9d7f49b01 SPIGOT-7548: Fix wrong spawn location for experience orb and dropped item Spigot Changes: ed9ba9a4 Drop no longer required patch ignoring -o option 86b5dd6a SPIGOT-7546: Fix hardcoded check for outdated client message aa7cde7a Remove obsolete APIs for per world view and simulation distances 6dff577e Remove obsolete patch preserving empty `ench` tags a3bf95b8 Remove obsolete PlayerLoginEvent#getRealAddress 1b02f5d6 Remove obsolete connected check on setScoreboard patch acf717eb Remove obsolete command block PermissibleBase patch 053fa2a9 Remove redundant patch dealing with null tile entities
2023-12-25 23:51:56 +01:00
index c9e3e104cd051a38e367653dc6c4f969665fc250..45ee0cd242271883412284625230822d9c8a5452 100644
2021-06-14 08:41:01 +02:00
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
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: cc9aa21a SPIGOT-6399, SPIGOT-7344: Clarify collidable behavior for player entities f23325b6 Add API for per-world simulation distances 26e1774e Add API for per-world view distances 0b541e60 Add PlayerLoginEvent#getRealAddress 5f027d2d PR-949: Add Vector#fromJOML() overloads for read-only vector types CraftBukkit Changes: bcf56171a PR-1321: Clean up some stuff which got missed during previous PRs 7f833a2d1 SPIGOT-7462: Players no longer drop XP after dying near a Sculk Catalyst 752aac669 Implement APIs for per world view and simulation distances 57d7ef433 Preserve empty enchantment tags for glow effect 465ec3fb4 Remove connected check on setScoreboard f90ce621e Use one PermissibleBase for all command blocks 5876cca44 SPIGOT-7550: Fix creation of Arrow instances f03fc3aa3 SPIGOT-7549: ServerTickManager#setTickRate incorrect Precondition 9d7f49b01 SPIGOT-7548: Fix wrong spawn location for experience orb and dropped item Spigot Changes: ed9ba9a4 Drop no longer required patch ignoring -o option 86b5dd6a SPIGOT-7546: Fix hardcoded check for outdated client message aa7cde7a Remove obsolete APIs for per world view and simulation distances 6dff577e Remove obsolete patch preserving empty `ench` tags a3bf95b8 Remove obsolete PlayerLoginEvent#getRealAddress 1b02f5d6 Remove obsolete connected check on setScoreboard patch acf717eb Remove obsolete command block PermissibleBase patch 053fa2a9 Remove redundant patch dealing with null tile entities
2023-12-25 23:51:56 +01:00
@@ -878,6 +878,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-14 08:41:01 +02:00
} 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) {
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: cc9aa21a SPIGOT-6399, SPIGOT-7344: Clarify collidable behavior for player entities f23325b6 Add API for per-world simulation distances 26e1774e Add API for per-world view distances 0b541e60 Add PlayerLoginEvent#getRealAddress 5f027d2d PR-949: Add Vector#fromJOML() overloads for read-only vector types CraftBukkit Changes: bcf56171a PR-1321: Clean up some stuff which got missed during previous PRs 7f833a2d1 SPIGOT-7462: Players no longer drop XP after dying near a Sculk Catalyst 752aac669 Implement APIs for per world view and simulation distances 57d7ef433 Preserve empty enchantment tags for glow effect 465ec3fb4 Remove connected check on setScoreboard f90ce621e Use one PermissibleBase for all command blocks 5876cca44 SPIGOT-7550: Fix creation of Arrow instances f03fc3aa3 SPIGOT-7549: ServerTickManager#setTickRate incorrect Precondition 9d7f49b01 SPIGOT-7548: Fix wrong spawn location for experience orb and dropped item Spigot Changes: ed9ba9a4 Drop no longer required patch ignoring -o option 86b5dd6a SPIGOT-7546: Fix hardcoded check for outdated client message aa7cde7a Remove obsolete APIs for per world view and simulation distances 6dff577e Remove obsolete patch preserving empty `ench` tags a3bf95b8 Remove obsolete PlayerLoginEvent#getRealAddress 1b02f5d6 Remove obsolete connected check on setScoreboard patch acf717eb Remove obsolete command block PermissibleBase patch 053fa2a9 Remove redundant patch dealing with null tile entities
2023-12-25 23:51:56 +01:00
@@ -920,7 +921,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-14 08:41:01 +02:00
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 c7de5cd2cca4580ef7ff59763eae3c8d6eef209c..98de2c14e146f862adc37fde428cf6c46d98d790 100644
2021-06-14 08:41:01 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
2023-12-05 23:12:48 +01:00
@@ -223,6 +223,9 @@ public class ServerLevel extends Level implements WorldGenLevel {
2021-06-14 08:41:01 +02:00
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);
@@ -1437,7 +1440,28 @@ public class ServerLevel extends Level implements WorldGenLevel {
2021-06-14 08:41:01 +02:00
// CraftBukkit start
2021-11-23 16:04:41 +01:00
private boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
2021-06-14 08:41:01 +02:00
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
2021-11-23 16:04:41 +01:00
// WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getKey(entity.getType())); // CraftBukkit
2021-06-14 08:41:01 +02:00
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
2023-12-06 20:40:37 +01:00
index 17cae197f76e02491791c55554bd57592a30aa1d..7be66f8649d6f6cb67e3b42e8f4fe739f0ff9f9f 100644
2021-06-14 08:41:01 +02:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
2023-12-05 23:12:48 +01:00
@@ -239,6 +239,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
2021-06-14 08:41:01 +02:00
public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper
private CraftEntity bukkitEntity;
+ public @org.jetbrains.annotations.Nullable net.minecraft.server.level.ChunkMap.TrackedEntity tracker; // Paper
2022-02-28 23:02:20 +01:00
+ public @Nullable Throwable addedToWorldStack; // Paper - entity debug
2021-06-14 08:41:01 +02:00
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 7f7e28808aaf5b858415532d85c246999bc71ed0..b4f7e73fa673006ad0f8ea5a8de5a825aa75e41c 100644
2021-06-14 08:41:01 +02:00
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
2023-12-05 23:12:48 +01:00
@@ -153,6 +153,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-06-14 08:41:01 +02:00
public boolean pvpMode;
public boolean keepSpawnInMemory = true;
public org.bukkit.generator.ChunkGenerator generator;
+ public static final boolean DEBUG_ENTITIES = Boolean.getBoolean("debug.entities"); // Paper
2021-07-07 08:52:40 +02:00
public boolean preventPoiUpdated = false; // CraftBukkit - SPIGOT-5710
2021-06-14 08:41:01 +02:00
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
2023-09-22 19:59:56 +02:00
index 21a2800db22f287b9c6a8290326fdf3b94ae94b1..d45d832232be5017dde53816191c2b1830a0da32 100644
2021-06-14 08:41:01 +02:00
--- a/src/main/java/net/minecraft/world/level/entity/EntityLookup.java
+++ b/src/main/java/net/minecraft/world/level/entity/EntityLookup.java
2022-02-28 23:02:20 +01:00
@@ -34,6 +34,26 @@ public class EntityLookup<T extends EntityAccess> {
2021-06-14 08:41:01 +02:00
UUID uUID = entity.getUUID();
if (this.byUuid.containsKey(uUID)) {
LOGGER.warn("Duplicate entity UUID {}: {}", uUID, entity);
+ // Paper start - extra debug info
2022-02-28 23:02:20 +01:00
+ if (entity instanceof net.minecraft.world.entity.Entity entityCast) {
2021-06-14 08:41:01 +02:00
+ if (net.minecraft.server.level.ServerLevel.DEBUG_ENTITIES) {
2022-02-28 23:02:20 +01:00
+ entityCast.addedToWorldStack = net.minecraft.server.level.ServerLevel.getAddToWorldStackTrace(entityCast);
2021-06-14 08:41:01 +02:00
+ }
+
+ T old = this.byUuid.get(entity.getUUID());
2022-02-28 23:02:20 +01:00
+ 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);
2021-06-14 08:41:01 +02:00
+ if (net.minecraft.server.level.ServerLevel.DEBUG_ENTITIES) {
2022-02-28 23:02:20 +01:00
+ if (oldCast.addedToWorldStack != null) {
+ oldCast.addedToWorldStack.printStackTrace();
2021-06-14 08:41:01 +02:00
+ } else {
2022-02-28 23:02:20 +01:00
+ LOGGER.error("Oddly, the old entity was not added to the world in the normal way. Plugins?");
2021-06-14 08:41:01 +02:00
+ }
2022-02-28 23:02:20 +01:00
+ entityCast.addedToWorldStack.printStackTrace();
2021-06-14 08:41:01 +02:00
+ }
+ }
+ }
+ // Paper end
} else {
this.byUuid.put(uUID, entity);
this.byId.put(entity.getId(), entity);