2021-06-14 06:41:01 +00: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
|
2022-03-13 07:47:54 +00:00
|
|
|
index 81eb73e9fde37e3b196bd899ecd4d614897d1a98..4206e1c96cdc7b7e324331681215f735688dd558 100644
|
2021-06-14 06:41:01 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
2022-03-13 07:47:54 +00:00
|
|
|
@@ -1353,6 +1353,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
2021-06-14 06:41:01 +00: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) {
|
2022-03-13 07:47:54 +00:00
|
|
|
@@ -1395,7 +1396,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
2021-06-14 06:41:01 +00: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
|
2022-03-13 07:47:54 +00:00
|
|
|
index 4d69b6b35f04c904ee9ca9c896baaa9892f8ef9c..5f58aa648a5f0c3e61f6d9d5853583ca003e3620 100644
|
2021-06-14 06:41:01 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
2022-03-01 05:43:03 +00:00
|
|
|
@@ -209,6 +209,9 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
2021-06-14 06:41:01 +00: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);
|
2022-03-13 07:47:54 +00:00
|
|
|
@@ -1099,7 +1102,28 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
2021-06-14 06:41:01 +00:00
|
|
|
// CraftBukkit start
|
2021-11-23 15:04:41 +00:00
|
|
|
private boolean addEntity(Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
|
2021-06-14 06:41:01 +00: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 15:04:41 +00:00
|
|
|
// WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getKey(entity.getType())); // CraftBukkit
|
2021-06-14 06:41:01 +00: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
|
2022-02-28 22:02:20 +00:00
|
|
|
index 919b66c88f21606348b20f02cc420d0ff1fa0f8b..ad2341ce26f976b4c45d91e8040bea5aef130f02 100644
|
2021-06-14 06:41:01 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
2022-03-01 05:43:03 +00:00
|
|
|
@@ -173,6 +173,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, i
|
2021-06-14 06:41:01 +00:00
|
|
|
public com.destroystokyo.paper.loottable.PaperLootableInventoryData lootableData; // Paper
|
|
|
|
private CraftEntity bukkitEntity;
|
|
|
|
|
2021-12-13 04:31:32 +00:00
|
|
|
+ public @org.jetbrains.annotations.Nullable net.minecraft.server.level.ChunkMap.TrackedEntity tracker; // Paper
|
2022-02-28 22:02:20 +00:00
|
|
|
+ public @Nullable Throwable addedToWorldStack; // Paper - entity debug
|
2021-06-14 06:41:01 +00: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
|
2022-03-01 05:43:03 +00:00
|
|
|
index 67566e5f95f7452d31bea485bdb91a4e1a32e5d5..dc2235824853a0d7ccbff51dd26a71e97fe90ba7 100644
|
2021-06-14 06:41:01 +00:00
|
|
|
--- a/src/main/java/net/minecraft/world/level/Level.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/level/Level.java
|
2022-03-01 05:43:03 +00:00
|
|
|
@@ -142,6 +142,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
|
2021-06-14 06:41:01 +00: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 06:52:40 +00:00
|
|
|
public boolean preventPoiUpdated = false; // CraftBukkit - SPIGOT-5710
|
2021-06-14 06:41:01 +00: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
|
2022-03-01 03:25:13 +00:00
|
|
|
index e6b9f812e521abd552e0c7dc0429d5a62f2bfc35..f4731d69946871768ecf16149a47d2ef1cb3e910 100644
|
2021-06-14 06:41:01 +00: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 22:02:20 +00:00
|
|
|
@@ -34,6 +34,26 @@ public class EntityLookup<T extends EntityAccess> {
|
2021-06-14 06:41:01 +00: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 22:02:20 +00:00
|
|
|
+ if (entity instanceof net.minecraft.world.entity.Entity entityCast) {
|
2021-06-14 06:41:01 +00:00
|
|
|
+ if (net.minecraft.server.level.ServerLevel.DEBUG_ENTITIES) {
|
2022-02-28 22:02:20 +00:00
|
|
|
+ entityCast.addedToWorldStack = net.minecraft.server.level.ServerLevel.getAddToWorldStackTrace(entityCast);
|
2021-06-14 06:41:01 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ T old = this.byUuid.get(entity.getUUID());
|
2022-02-28 22:02:20 +00: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 06:41:01 +00:00
|
|
|
+ if (net.minecraft.server.level.ServerLevel.DEBUG_ENTITIES) {
|
2022-02-28 22:02:20 +00:00
|
|
|
+ if (oldCast.addedToWorldStack != null) {
|
|
|
|
+ oldCast.addedToWorldStack.printStackTrace();
|
2021-06-14 06:41:01 +00:00
|
|
|
+ } else {
|
2022-02-28 22:02:20 +00:00
|
|
|
+ LOGGER.error("Oddly, the old entity was not added to the world in the normal way. Plugins?");
|
2021-06-14 06:41:01 +00:00
|
|
|
+ }
|
2022-02-28 22:02:20 +00:00
|
|
|
+ entityCast.addedToWorldStack.printStackTrace();
|
2021-06-14 06:41:01 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
} else {
|
|
|
|
this.byUuid.put(uUID, entity);
|
|
|
|
this.byId.put(entity.getId(), entity);
|