ClientboundPlayerPositionPacket 0x49

ClientboundPlayerPositionPacket: Minecraft 26.3 packet (0x49 Play clientbound). Wire name 'player_position', fields: id, change, relatives, handled

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x4973PLAYClientboundGamePacketTypes.CLIENTBOUND_PLAYER_POSITION: "player_position"

Packet ids are positional: the id is the index of the addPacket call in the protocol builder (see ProtocolInfoBuilder.listPackets). Ids change between game versions.

Wire fields (3)

FieldType
idint
changePositionMoveRotation
relativesSet<Relative>

Fields are the components of the packet record.

Stream codec

static final StreamCodec<FriendlyByteBuf, ClientboundPlayerPositionPacket> STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.VAR_INT, ClientboundPlayerPositionPacket::id, PositionMoveRotation.STREAM

Modern packets serialize through StreamCodecs instead of read/write methods.

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleMovePlayer(ClientboundPlayerPositionPacket clientboundplayerpositionpacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundPlayerPositionPacket.java36 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import java.util.Set;
4
import net.minecraft.network.FriendlyByteBuf;
5
import net.minecraft.network.codec.ByteBufCodecs;
6
import net.minecraft.network.codec.StreamCodec;
7
import net.minecraft.network.protocol.Packet;
8
import net.minecraft.network.protocol.PacketType;
9
import net.minecraft.world.entity.PositionMoveRotation;
10
import net.minecraft.world.entity.Relative;
11
12
public record ClientboundPlayerPositionPacket(int id, PositionMoveRotation change, Set<Relative> relatives) implements Packet<ClientGamePacketListener> {
13
	public static final StreamCodec<FriendlyByteBuf, ClientboundPlayerPositionPacket> STREAM_CODEC = StreamCodec.composite(
14
		ByteBufCodecs.VAR_INT,
15
		ClientboundPlayerPositionPacket::id,
16
		PositionMoveRotation.STREAM_CODEC,
17
		ClientboundPlayerPositionPacket::change,
18
		Relative.SET_STREAM_CODEC,
19
		ClientboundPlayerPositionPacket::relatives,
20
		ClientboundPlayerPositionPacket::new
21
	);
22
23
	public static ClientboundPlayerPositionPacket of(final int id, final PositionMoveRotation values, final Set<Relative> relatives) {
24
		return new ClientboundPlayerPositionPacket(id, values, relatives);
25
	}
26
27
	@Override
28
	public PacketType<ClientboundPlayerPositionPacket> type() {
29
		return GamePacketTypes.CLIENTBOUND_PLAYER_POSITION;
30
	}
31
32
	public void handle(final ClientGamePacketListener listener) {
33
		listener.handleMovePlayer(this);
34
	}
35
}
36