mojira.dev
MC-307977

Joining a dimension with an entity that shares your UUID locks you out of the world

The bug

If the player loads into a dimension in which there already exists a loaded entity with the player’s UUID, the “Loading terrain…” screen never ends. After restarting the game, attempting to join the world will instantly disconnect the player, even in singleplayer.

This has been an issue for a while, since at least 1.15.

How to reproduce

  1. Find your UUID: /data get entity @p UUID

  2. Summon a mob with that UUID in the nether: /execute in the_nether run summon cow ~ ~ ~ {UUID:[I;...]}

  3. Enter the nether: /execute in the_nether run tp @p ~ ~ ~

Expected result

You should load into the dimension, and the cow should probably be discarded

Observed result

The log indicates that “There was an unexpected error running that command”

You are stuck on the “Loading terrain” screen forever

After quitting the game and rejoining, this error is logged and the player is disconnected

[10:55:34] [Server thread/ERROR]: Couldn't place player in world
java.lang.ClassCastException: class net.minecraft.world.entity.animal.cow.Cow cannot be cast to class net.minecraft.server.level.ServerPlayer (net.minecraft.world.entity.animal.cow.Cow and net.minecraft.server.level.ServerPlayer are in unnamed module of loader 'app')
	at net.minecraft.server.level.ServerLevel.addPlayer(ServerLevel.java:1008)
	at net.minecraft.server.level.ServerLevel.addNewPlayer(ServerLevel.java:996)
	at net.minecraft.server.players.PlayerList.placeNewPlayer(PlayerList.java:223)
	at net.minecraft.server.network.config.PrepareSpawnTask$Ready.spawn(PrepareSpawnTask.java:198)
	at net.minecraft.server.network.config.PrepareSpawnTask.spawnPlayer(PrepareSpawnTask.java:91)
	at net.minecraft.server.network.ServerConfigurationPacketListenerImpl.handleConfigurationFinished(ServerConfigurationPacketListenerImpl.java:178)
	at net.minecraft.network.protocol.configuration.ServerboundFinishConfigurationPacket.handle(ServerboundFinishConfigurationPacket.java:22)
	at net.minecraft.network.protocol.configuration.ServerboundFinishConfigurationPacket.handle(ServerboundFinishConfigurationPacket.java:8)
	at net.minecraft.network.PacketProcessor$ListenerAndPacket.handle(PacketProcessor.java:55)
	at net.minecraft.network.PacketProcessor.processQueuedPackets(PacketProcessor.java:38)
	at net.minecraft.server.MinecraftServer.processPacketsAndTick(MinecraftServer.java:1032)
	at net.minecraft.client.server.IntegratedServer.processPacketsAndTick(IntegratedServer.java:104)
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:773)
	at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:320)
	at java.base/java.lang.Thread.run(Thread.java:1516)

Linked issues

Comments 2

This might duplicate MC-195337 actually, although it’s not clear why that report doesn’t mention getting locked out of the world.

Code analysis (from ServerLevel.addPlayer)

Entity existing = this.getEntity(player.getUUID());
if (existing != null) {
    LOGGER.warn("Force-added player with duplicate UUID {}", player.getUUID());
    existing.unRide();
    this.removePlayerImmediately((ServerPlayer)existing, RemovalReason.DISCARDED);
}

If the existing entity isn’t a player, it still gets cast to ServerPlayer, which causes a ClassCastException. All that would need to be done to fix this is to omit the cast and replace the call to removePlayerImmediately with a call to existing.remove with the same arguments. This mirrors existing functionality but expands it to all entities.

tryashtar

(Unassigned)

Confirmed

Platform

Low

Commands

26.1.2, 26.2 Snapshot 6

Retrieved