--- a/net/minecraft/world/level/entity/EntityLookup.java
+++ b/net/minecraft/world/level/entity/EntityLookup.java
@@ -20,7 +20,7 @@
         for(T entityAccess : this.byId.values()) {
             U entityAccess2 = (U)((EntityAccess)filter.tryCast(entityAccess));
             if (entityAccess2 != null) {
-                action.accept((T)entityAccess2);
+                action.accept(entityAccess2); // Paper - decompile fix
             }
         }
 
@@ -34,6 +34,26 @@
         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);
