ClientboundRotateHeadPacket 0x55

ClientboundRotateHeadPacket: Minecraft 26.3 packet (0x55 Play clientbound). Wire name 'rotate_head', fields: entity, yHeadRot, handled

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x5585PLAYClientboundGamePacketTypes.CLIENTBOUND_ROTATE_HEAD: "rotate_head"

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

FieldType
entityEntity
yHeadRotbyte

Stream codec

static final StreamCodec<FriendlyByteBuf, ClientboundRotateHeadPacket> STREAM_CODEC = Packet.codec( ClientboundRotateHeadPacket::write, ClientboundRotateHeadPacket::new );

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleRotateMob(ClientboundRotateHeadPacket clientboundrotateheadpacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundRotateHeadPacket.java51 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.StreamCodec;
5
import net.minecraft.network.protocol.Packet;
6
import net.minecraft.network.protocol.PacketType;
7
import net.minecraft.util.Mth;
8
import net.minecraft.world.entity.Entity;
9
import net.minecraft.world.level.Level;
10
import org.jspecify.annotations.Nullable;
11
12
public class ClientboundRotateHeadPacket implements Packet<ClientGamePacketListener> {
13
	public static final StreamCodec<FriendlyByteBuf, ClientboundRotateHeadPacket> STREAM_CODEC = Packet.codec(
14
		ClientboundRotateHeadPacket::write, ClientboundRotateHeadPacket::new
15
	);
16
	private final int entityId;
17
	private final byte yHeadRot;
18
19
	public ClientboundRotateHeadPacket(final Entity entity, final byte yHeadRot) {
20
		this.entityId = entity.getId();
21
		this.yHeadRot = yHeadRot;
22
	}
23
24
	private ClientboundRotateHeadPacket(final FriendlyByteBuf input) {
25
		this.entityId = input.readVarInt();
26
		this.yHeadRot = input.readByte();
27
	}
28
29
	private void write(final FriendlyByteBuf output) {
30
		output.writeVarInt(this.entityId);
31
		output.writeByte(this.yHeadRot);
32
	}
33
34
	@Override
35
	public PacketType<ClientboundRotateHeadPacket> type() {
36
		return GamePacketTypes.CLIENTBOUND_ROTATE_HEAD;
37
	}
38
39
	public void handle(final ClientGamePacketListener listener) {
40
		listener.handleRotateMob(this);
41
	}
42
43
	public @Nullable Entity getEntity(final Level level) {
44
		return level.getEntity(this.entityId);
45
	}
46
47
	public float getYHeadRot() {
48
		return Mth.unpackDegrees(this.yHeadRot);
49
	}
50
}
51