ServerboundSetCarriedItemPacket 0x36

ServerboundSetCarriedItemPacket: Minecraft 26.3 packet (0x36 Play serverbound). Wire name 'set_carried_item', fields: slot, handled

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x3654PLAYServerboundGamePacketTypes.SERVERBOUND_SET_CARRIED_ITEM: "set_carried_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 (1)

FieldType
slotint

Stream codec

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

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleSetCarriedItem(ServerboundSetCarriedItemPacket serverboundsetcarrieditempacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundSetCarriedItemPacket.java39 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
8
public class ServerboundSetCarriedItemPacket implements Packet<ServerGamePacketListener> {
9
	public static final StreamCodec<FriendlyByteBuf, ServerboundSetCarriedItemPacket> STREAM_CODEC = Packet.codec(
10
		ServerboundSetCarriedItemPacket::write, ServerboundSetCarriedItemPacket::new
11
	);
12
	private final int slot;
13
14
	public ServerboundSetCarriedItemPacket(final int slot) {
15
		this.slot = slot;
16
	}
17
18
	private ServerboundSetCarriedItemPacket(final FriendlyByteBuf input) {
19
		this.slot = input.readShort();
20
	}
21
22
	private void write(final FriendlyByteBuf output) {
23
		output.writeShort(this.slot);
24
	}
25
26
	@Override
27
	public PacketType<ServerboundSetCarriedItemPacket> type() {
28
		return GamePacketTypes.SERVERBOUND_SET_CARRIED_ITEM;
29
	}
30
31
	public void handle(final ServerGamePacketListener listener) {
32
		listener.handleSetCarriedItem(this);
33
	}
34
35
	public int getSlot() {
36
		return this.slot;
37
	}
38
}
39