ServerboundSelectBundleItemPacket 0x03

ServerboundSelectBundleItemPacket: Minecraft 26.3 packet (0x03 Play serverbound). Wire name 'bundle_item_selected', fields: slotId, selectedItemIndex

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x033PLAYServerboundGamePacketTypes.SERVERBOUND_BUNDLE_ITEM_SELECTED: "bundle_item_selected"

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
slotIdint
selectedItemIndexint

Fields are the components of the packet record.

Stream codec

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

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleBundleItemSelectedPacket(ServerboundSelectBundleItemPacket serverboundselectbundleitempacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundSelectBundleItemPacket.java34 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 record ServerboundSelectBundleItemPacket(int slotId, int selectedItemIndex) implements Packet<ServerGamePacketListener> {
9
	public static final StreamCodec<FriendlyByteBuf, ServerboundSelectBundleItemPacket> STREAM_CODEC = Packet.codec(
10
		ServerboundSelectBundleItemPacket::write, ServerboundSelectBundleItemPacket::new
11
	);
12
13
	private ServerboundSelectBundleItemPacket(final FriendlyByteBuf input) {
14
		this(input.readVarInt(), input.readVarInt());
15
		if (this.selectedItemIndex < 0 && this.selectedItemIndex != -1) {
16
			throw new IllegalArgumentException("Invalid selectedItemIndex: " + this.selectedItemIndex);
17
		}
18
	}
19
20
	private void write(final FriendlyByteBuf output) {
21
		output.writeVarInt(this.slotId);
22
		output.writeVarInt(this.selectedItemIndex);
23
	}
24
25
	@Override
26
	public PacketType<ServerboundSelectBundleItemPacket> type() {
27
		return GamePacketTypes.SERVERBOUND_BUNDLE_ITEM_SELECTED;
28
	}
29
30
	public void handle(final ServerGamePacketListener listener) {
31
		listener.handleBundleItemSelectedPacket(this);
32
	}
33
}
34