ServerboundUseItemOnPacket 0x42

ServerboundUseItemOnPacket: Minecraft 26.3 packet (0x42 Play serverbound). Wire name 'use_item_on', fields: hand, hitResult, sequence, handled

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x4266PLAYServerboundGamePacketTypes.SERVERBOUND_USE_ITEM_ON: "use_item_on"

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
handInteractionHand
hitResultBlockHitResult
sequenceint

Fields are the components of the packet record.

Stream codec

static final StreamCodec<FriendlyByteBuf, ServerboundUseItemOnPacket> STREAM_CODEC = StreamCodec.composite( InteractionHand.STREAM_CODEC, ServerboundUseItemOnPacket::hand, BlockHitResult.STREAM_CODEC,

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleUseItemOn(ServerboundUseItemOnPacket serverbounduseitemonpacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundUseItemOnPacket.java31 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
import net.minecraft.world.phys.BlockHitResult;
10
11
public record ServerboundUseItemOnPacket(InteractionHand hand, BlockHitResult hitResult, int sequence) implements Packet<ServerGamePacketListener> {
12
	public static final StreamCodec<FriendlyByteBuf, ServerboundUseItemOnPacket> STREAM_CODEC = StreamCodec.composite(
13
		InteractionHand.STREAM_CODEC,
14
		ServerboundUseItemOnPacket::hand,
15
		BlockHitResult.STREAM_CODEC,
16
		ServerboundUseItemOnPacket::hitResult,
17
		ByteBufCodecs.VAR_INT,
18
		ServerboundUseItemOnPacket::sequence,
19
		ServerboundUseItemOnPacket::new
20
	);
21
22
	@Override
23
	public PacketType<ServerboundUseItemOnPacket> type() {
24
		return GamePacketTypes.SERVERBOUND_USE_ITEM_ON;
25
	}
26
27
	public void handle(final ServerGamePacketListener listener) {
28
		listener.handleUseItemOn(this);
29
	}
30
}
31