From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 21 Jul 2018 08:25:40 -0400 Subject: [PATCH] Add Debug Entities option to debug dupe uuid issues diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java index c9e3e104cd051a38e367653dc6c4f969665fc250..45ee0cd242271883412284625230822d9c8a5452 100644 --- a/src/main/java/net/minecraft/server/level/ChunkMap.java +++ b/src/main/java/net/minecraft/server/level/ChunkMap.java @@ -878,6 +878,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) { @@ -920,7 +921,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 0bb2ed82e8a3dffa9fd9d7aa41685dd50dafac0c..8168a9a3f2b166775a531e7f834710669845d0ae 100644 --- a/src/main/java/net/minecraft/server/level/ServerLevel.java +++ b/src/main/java/net/minecraft/server/level/ServerLevel.java @@ -1436,6 +1436,12 @@ 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 - extra debug info + if (entity.valid) { + MinecraftServer.LOGGER.error("Attempted Double World add on {}", entity, new Throwable()); + return true; + } + // Paper end - extra debug info if (entity.isRemoved()) { // WorldServer.LOGGER.warn("Tried to add entity {} but it was marked as removed already", EntityTypes.getKey(entity.getType())); // CraftBukkit return false; diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java index ad2e61c7fd7906477e30e91c826d9ce4fb6bffc0..bbb6abd5a51a0ffef41f2ee38eb6d7a21d1c6c23 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -241,6 +241,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S 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 CraftEntity getBukkitEntity() { if (this.bukkitEntity == null) { this.bukkitEntity = CraftEntity.getEntity(this.level.getCraftServer(), this); 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 21a2800db22f287b9c6a8290326fdf3b94ae94b1..2e561ac90a8c91ea13cfc18d09f8e0abbcff9385 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,14 @@ public class EntityLookup { 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) { + final T old = this.byUuid.get(entity.getUUID()); + if (old instanceof net.minecraft.world.entity.Entity oldCast && oldCast.getId() != entity.getId() && oldCast.valid) { + LOGGER.error("Overwrote an existing entity {} with {}", oldCast, entity); + } + } + // Paper end - extra debug info } else { this.byUuid.put(uUID, entity); this.byId.put(entity.getId(), entity);