ClientboundEntityPositionSyncPacket 0x23

ClientboundEntityPositionSyncPacket: Minecraft 26.3 packet (0x23 Play clientbound). Wire name 'entity_position_sync', fields: id, position, yRot, xRot

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x2335PLAYClientboundGamePacketTypes.CLIENTBOUND_ENTITY_POSITION_SYNC: "entity_position_sync"

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 (5)

FieldType
idint
positionPositionPath
yRotfloat
xRotfloat
onGroundboolean

Fields are the components of the packet record.

Stream codec

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

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleEntityPositionSync(ClientboundEntityPositionSyncPacket clientboundentitypositionsyncpacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundEntityPositionSyncPacket.java53 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import net.minecraft.network.FriendlyByteBuf;
4
import net.minecraft.network.codec.ByteBufCodecs;
5
import net.minecraft.network.codec.StreamCodec;
6
import net.minecraft.network.protocol.PacketType;
7
import net.minecraft.world.entity.Entity;
8
import net.minecraft.world.entity.PositionPath;
9
10
public record ClientboundEntityPositionSyncPacket(int id, PositionPath position, float yRot, float xRot, boolean onGround)
11
	implements MovementPacket<ClientGamePacketListener> {
12
	public static final StreamCodec<FriendlyByteBuf, ClientboundEntityPositionSyncPacket> STREAM_CODEC = StreamCodec.composite(
13
		ByteBufCodecs.VAR_INT,
14
		ClientboundEntityPositionSyncPacket::id,
15
		PositionPath.STREAM_CODEC,
16
		ClientboundEntityPositionSyncPacket::position,
17
		ByteBufCodecs.FLOAT,
18
		ClientboundEntityPositionSyncPacket::yRot,
19
		ByteBufCodecs.FLOAT,
20
		ClientboundEntityPositionSyncPacket::xRot,
21
		ByteBufCodecs.BOOL,
22
		ClientboundEntityPositionSyncPacket::onGround,
23
		ClientboundEntityPositionSyncPacket::new
24
	);
25
26
	public static ClientboundEntityPositionSyncPacket of(final Entity entity, final PositionPath position) {
27
		return new ClientboundEntityPositionSyncPacket(entity.getId(), position, entity.getYRot(), entity.getXRot(), entity.onGround());
28
	}
29
30
	public static ClientboundEntityPositionSyncPacket of(final Entity entity) {
31
		return of(entity, PositionPath.of(entity.trackingPosition()));
32
	}
33
34
	@Override
35
	public PacketType<ClientboundEntityPositionSyncPacket> type() {
36
		return GamePacketTypes.CLIENTBOUND_ENTITY_POSITION_SYNC;
37
	}
38
39
	public void handle(final ClientGamePacketListener listener) {
40
		listener.handleEntityPositionSync(this);
41
	}
42
43
	@Override
44
	public boolean hasPosition() {
45
		return true;
46
	}
47
48
	@Override
49
	public boolean hasRotation() {
50
		return true;
51
	}
52
}
53