ServerboundUseItemPacket 0x43

ServerboundUseItemPacket: Minecraft 26.3 packet (0x43 Play serverbound). Wire name 'use_item', fields: hand, sequence, yRot, xRot, handled

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x4367PLAYServerboundGamePacketTypes.SERVERBOUND_USE_ITEM: "use_item"

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

FieldType
handInteractionHand
sequenceint
yRotfloat
xRotfloat

Fields are the components of the packet record.

Stream codec

static final StreamCodec<FriendlyByteBuf, ServerboundUseItemPacket> STREAM_CODEC = StreamCodec.composite( InteractionHand.STREAM_CODEC, ServerboundUseItemPacket::hand, ByteBufCodecs.VAR_INT, Serverbou

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleUseItem(ServerboundUseItemPacket serverbounduseitempacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundUseItemPacket.java32 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.Packet;
7
import net.minecraft.network.protocol.PacketType;
8
import net.minecraft.world.InteractionHand;
9
10
public record ServerboundUseItemPacket(InteractionHand hand, int sequence, float yRot, float xRot) implements Packet<ServerGamePacketListener> {
11
	public static final StreamCodec<FriendlyByteBuf, ServerboundUseItemPacket> STREAM_CODEC = StreamCodec.composite(
12
		InteractionHand.STREAM_CODEC,
13
		ServerboundUseItemPacket::hand,
14
		ByteBufCodecs.VAR_INT,
15
		ServerboundUseItemPacket::sequence,
16
		ByteBufCodecs.FLOAT,
17
		ServerboundUseItemPacket::yRot,
18
		ByteBufCodecs.FLOAT,
19
		ServerboundUseItemPacket::xRot,
20
		ServerboundUseItemPacket::new
21
	);
22
23
	@Override
24
	public PacketType<ServerboundUseItemPacket> type() {
25
		return GamePacketTypes.SERVERBOUND_USE_ITEM;
26
	}
27
28
	public void handle(final ServerGamePacketListener listener) {
29
		listener.handleUseItem(this);
30
	}
31
}
32