Skip to content

update entity_teleport packet on 1.21.3+#1154

Open
TheSharkyOfficial wants to merge 3 commits into
PrismarineJS:masterfrom
TheSharkyOfficial:patch-1
Open

update entity_teleport packet on 1.21.3+#1154
TheSharkyOfficial wants to merge 3 commits into
PrismarineJS:masterfrom
TheSharkyOfficial:patch-1

Conversation

@TheSharkyOfficial

Copy link
Copy Markdown

Updated teleport_entity packet according to https://minecraft.wiki/w/Java_Edition_protocol/Packets#Synchronize_Vehicle_Position
Should fix partial packet errors for this packet.

@extremeheat

Copy link
Copy Markdown
Member

Do you have link to relevant vanilla source code for this?

@atiweb

atiweb commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Re: the vanilla source — here's the relevant code, decompiled from the server jar (ClientboundTeleportEntityPacket):

public record ClientboundTeleportEntityPacket(int id, PositionMoveRotation change, Set<Relative> relatives, boolean onGround) {
    public static final StreamCodec<FriendlyByteBuf, ClientboundTeleportEntityPacket> STREAM_CODEC = StreamCodec.composite(
        ByteBufCodecs.VAR_INT,             ClientboundTeleportEntityPacket::id,
        PositionMoveRotation.STREAM_CODEC, ClientboundTeleportEntityPacket::change,
        Relative.SET_STREAM_CODEC,         ClientboundTeleportEntityPacket::relatives,
        ByteBufCodecs.BOOL,                ClientboundTeleportEntityPacket::onGround,
        ClientboundTeleportEntityPacket::new);
}
public record PositionMoveRotation(Vec3 position, Vec3 deltaMovement, float yRot, float xRot) { /* Vec3, Vec3, FLOAT, FLOAT */ }

So the wire layout is id(varint), position x/y/z (f64), deltaMovement x/y/z (f64), yRot/xRot (f32), relatives, onGround(bool). The position / velocity / f32-rotation / onGround part of this PR matches. I checked the codec is byte-for-byte the same in 1.21.3, 1.21.11 and 26.2, so it's been stable since the 1.21.2 rework.

Two things worth fixing:

1. flags is a 4-byte int, not a 9-bit bitfield. Relative.SET_STREAM_CODEC is:

public enum Relative { X(0), Y(1), Z(2), Y_ROT(3), X_ROT(4), DELTA_X(5), DELTA_Y(6), DELTA_Z(7), ROTATE_DELTA(8); }
public static final StreamCodec<ByteBuf, Set<Relative>> SET_STREAM_CODEC = ByteBufCodecs.INT.map(Relative::unpack, Relative::pack);

— a 4-byte int with bits 0–8. The inline bitfield of 9×1 bits here only consumes 2 bytes (and reads MSB-first), so it would still desync. minecraft-data already has the right type for this exact Set<Relative>PositionUpdateRelatives (bitflags over u32), used by packet_position:

"PositionUpdateRelatives": ["bitflags", { "type": "u32", "flags": ["x","y","z","yaw","pitch","dx","dy","dz","yawDelta"] }]

So "type": "PositionUpdateRelatives" is a drop-in fix (correct width + reuses the existing type instead of a new inline bitfield).

2. This affects every 1.21.2+ version, not only 1.21.3. entity_teleport is still the old yaw/pitch: i8 form in 1.21.3, 1.21.6, 1.21.9 and 1.21.11 (and in the generated 26.2 data in #1198), and the jar structure is identical across all of them — so the same fix is needed everywhere from 1.21.2 onward.

@DatArnoGuy

Copy link
Copy Markdown

Is this ready to be merged? My console is again full of this spam :D

Chunk size is 64 but only 30 was read ; partial packet : {"name":"entity_teleport","params":{"entityId":791,"x":48.97947009945363,"y":60,"z":133.125,"yaw":21,"pitch":-72,"onGround":true}}; buffer :7b970640487d5f46b64817404e0000000000004060a4000000000015b82325d210bf270000000000000000000000000000000040f3e0ee000000000000000001

@extremeheat

Copy link
Copy Markdown
Member

@copilot Please correct the changes made per atiweb comment with PositionUpdateRelatives and also apply this to all subsequent versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants