mojira.dev
MC-263030

Camel passenger position incorrectly written to NBT, breaking data command and worldsave

Description

With multiple passengers on a camel, the data command and saving the world use wrong coordinates for the passengers' locations. The incorrectly saved coordinates also affect gameplay in the first world simulation step after reloading the chunks.

Steps to reproduce:

  1. Place a command block high up in the air and power it.

    /summon minecraft:camel ~ ~2 ~ {Passengers:[{id:"minecraft:pig"},{id:"minecraft:sheep"}]}
  2. Check the Position of the camel and passenger:

  3. [media]
    /data get entity @e[type=minecraft:pig,sort=nearest,limit=1] Pos

    Use F3+I on the pig, compare the coordinates. The coordinates are different.

Code Analysis

The position of the passenger and the camel are the same horizontally according to the command. However, the passengers are clearly offset sideways. Therefore the coordinates are incorrect. Code analysis shows that saving an Entity to an NBT tag explicitly uses the vehicle's X and Z coordinates. This is probably a historical artifact that does not consider the relatively new two passenger camels. F3+I seems to use a different method to find the entity coordinates.

if (this.vehicle != null) {
    nbt.put("Pos", this.toNbtList(this.vehicle.getX(), this.getY(), this.vehicle.getZ()));
} else {
    nbt.put("Pos", this.toNbtList(this.getX(), this.getY(), this.getZ()));
}

Proposed Solution

Do not store the vehicle's coordinates in the NBT. If the use of the vehicle's coordinates is a bugfix for another issue, the valid passenger position can be stored instead.

Attachments

Comments 1

Can confirm in 24w21b.

2No2Name

(Unassigned)

Community Consensus

Platform

Low

Commands, Save Data

1.20 Pre-release 6, 24w21b

Retrieved