mojira.dev
MC-151270

Teleporting an entity from another dimension can cause UUID duplication in entity sections

The bug

When teleporting an entity from another dimension, the entity is added to the entity sections in the destination dimension even though there are already entities with the same UUID as the teleported entity.

How to reproduce

  1. Mark the chunk [0, 0] in the overworld and the end to be force loaded.

    /execute in minecraft:overworld run forceload add 0 0
  2. /execute in minecraft:the_end run forceload add 0 0
  3. Let the overworld be the destination dimension and add an entity with the UUID 0-0-0-0-24ee6.

    /execute in minecraft:overworld run summon minecraft:item_frame 0 0 0 {UUID: [I; 0, 0, 0, 151270], Fixed: true, CustomName: '"151270"'}
  4. Let the end be the origin dimension and add an entity with the UUID 0-0-0-0-24ee6.

    /execute in minecraft:the_end run summon minecraft:item_frame 0 0 0 {UUID: [I; 0, 0, 0, 151270], Fixed: true, CustomName: '"151270"'}
  5. Teleport the entity in the end to the overworld.

    /execute in minecraft:the_end as @e[x=0, y=0, z=0, dx=0] in minecraft:overworld run teleport @s 0 0 0

    Keeping entity minecraft:item_frame that already exists with UUID 00000000-0000-0000-0000-000000024ee6

  6. Check entities in the entity sections.

    /execute in minecraft:overworld run say @e[x=0, y=0, z=0, dx=0]

    → ❌ 151270, 151270, the entity in the end is added to the entity sections in the overworld. The entity sections in the overworld now have two entities with the same UUID 0-0-0-0-24ee6.

Code analysis

// net.minecraft.server.level.ServerLevel

public void addFromAnotherDimension(Entity entity) {
    boolean forcedLoading = entity.forcedLoading;
    entity.forcedLoading = true;

    // Since this level already has an entity with the same UUID as `entity`, the game warns about UUID duplication and does not add `entity` to this level.
    this.addWithUUID(entity);
    entity.forcedLoading = forcedLoading;

    // However, `entity` is added to the entity sections in this level without UUID check.
    // UUID duplication in entity sections causes here.
    this.updateChunkPos(entity);
}

Comments

wobst.michael

Can you still reproduce this in the latest snapshot?

intsuc

Yes, this still affects 20w18a.

However, there are a few minor changes affecting the results. Before updating affected versions, I need to rework the description and the reproduction steps focusing on more reproducibility and UUID duplication.

intsuc

Fixed in 20w45a. When adding an entity, the game now checks the known UUIDs and prints the following warning message if its UUID is duplicated.

UUID of added entity already exists: ...

intsuc

(Unassigned)

Confirmed

Entities

/teleport, UUID, dimension, entity

Minecraft 1.14.1 Pre-Release 1, Minecraft 1.14.1 Pre-Release 2, Minecraft 1.14.1, Minecraft 1.14.2 Pre-Release 1, Minecraft 1.14.2 Pre-Release 2, ..., 20w29a, 1.16.2 Pre-release 1, 1.16.2, 1.16.3, 1.16.4 Pre-release 1

20w45a

Retrieved