ClientboundHurtAnimationPacket 0x2B

ClientboundHurtAnimationPacket: Minecraft 26.3 packet (0x2B Play clientbound). Wire name 'hurt_animation', fields: id, yaw, handled

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x2B43PLAYClientboundGamePacketTypes.CLIENTBOUND_HURT_ANIMATION: "hurt_animation"

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
idint
yawfloat

Fields are the components of the packet record.

Stream codec

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

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleHurtAnimation(ClientboundHurtAnimationPacket clientboundhurtanimationpacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundHurtAnimationPacket.java36 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.world.entity.LivingEntity;
8
9
public record ClientboundHurtAnimationPacket(int id, float yaw) implements Packet<ClientGamePacketListener> {
10
	public static final StreamCodec<FriendlyByteBuf, ClientboundHurtAnimationPacket> STREAM_CODEC = Packet.codec(
11
		ClientboundHurtAnimationPacket::write, ClientboundHurtAnimationPacket::new
12
	);
13
14
	public ClientboundHurtAnimationPacket(final LivingEntity entity) {
15
		this(entity.getId(), entity.getHurtDir());
16
	}
17
18
	private ClientboundHurtAnimationPacket(final FriendlyByteBuf input) {
19
		this(input.readVarInt(), input.readFloat());
20
	}
21
22
	private void write(final FriendlyByteBuf output) {
23
		output.writeVarInt(this.id);
24
		output.writeFloat(this.yaw);
25
	}
26
27
	@Override
28
	public PacketType<ClientboundHurtAnimationPacket> type() {
29
		return GamePacketTypes.CLIENTBOUND_HURT_ANIMATION;
30
	}
31
32
	public void handle(final ClientGamePacketListener listener) {
33
		listener.handleHurtAnimation(this);
34
	}
35
}
36