mojira.dev
MC-120669

Spawn eggs can spawn entities with already used UUID

The bug

Spawn eggs can spawn entities with already used UUIDs. This should not be possible since UUIDs are supposed to be unique and duplicate UUIDs can and will cause errors.

How to reproduce

  1. Give yourself a spawn egg

    /give @s spawn_egg{EntityTag:{id:"minecraft:husk",UUIDLeast:1L,UUIDMost:1L}}
    /give @s spawn_egg{EntityTag:{id:"minecraft:husk",UUIDLeast:1L,UUIDMost:1L}}
  2. Use the spawn egg at least twice

  3. Use the following command to list all entities with the used UUID

    /say @e[nbt={UUIDMost:1L,UUIDLeast:1L}]
    /say @e[nbt={UUIDMost:1L,UUIDLeast:1L}]

    → It lists multiple entities

Code analysis and fix note

Based on 1.12.2 decompiled using MCP 9.40

The method net.minecraft.item.ItemMonsterPlacer.applyItemEntityDataToEntity(World, EntityPlayer, ItemStack, Entity) is apparently supposed to use the randomly generated UUID instead of the provided one, however does this incorrectly by setting the original UUID before merging the NBT data, see also MC-98244.

However, this is not required and probably not the correct behavior. Since the entity is a new one, the method applyItemEntityDataToEntity does not have to do anything to prevent UUID manipulation. Instead the methods ItemMonsterPlacer.onItemUse(EntityPlayer, World, BlockPos, EnumHand, EnumFacing, float, float, float), ItemMonsterPlacer.onItemRightClick(World, EntityPlayer, EnumHand) and net.minecraft.init.Bootstrap.registerDispenserBehaviors().new BehaviorDefaultDispenseItem() {...}.dispenseStack(IBlockSource, ItemStack) should first create the entity, then apply the NBT data and then try to spawn it. This would then fail as expected like it is currently the case for armor stands.

Linked issues

Attachments

Comments 2

I made the report more generic since that is likely the bug which is causing the behavior you are seeing. If not please comment again 🙂

Seems to be fixed in 1.13.1, the spawn egg will not spawn another husk until the husk with the already used UUID despawns or dies.

MukiTanuki

(Unassigned)

Confirmed

UUID, spawn_egg

Minecraft 1.12.1, Minecraft 1.12.2, Minecraft 17w45b

Minecraft 1.13.1

Retrieved