ServerboundContainerClickPacket 0x12

ServerboundContainerClickPacket: Minecraft 26.3 packet (0x12 Play serverbound). Wire name 'container_click', fields: containerId, stateId, slotNum

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x1218PLAYServerboundGamePacketTypes.SERVERBOUND_CONTAINER_CLICK: "container_click"

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

FieldType
containerIdint
stateIdint
slotNumshort
buttonNumbyte
containerInputContainerInput
changedSlotsInt2ObjectMap<HashedStack>
carriedItemHashedStack

Fields are the components of the packet record.

Stream codec

static final StreamCodec<RegistryFriendlyByteBuf, Int2ObjectMap<HashedStack>> SLOTS_STREAM_CODEC = ByteBufCodecs.map( Int2ObjectOpenHashMap::new, ByteBufCodecs.SHORT.map(Short::intValue, Integer::shor

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleContainerClick(ServerboundContainerClickPacket serverboundcontainerclickpacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundContainerClickPacket.java52 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
4
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
5
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
6
import net.minecraft.network.HashedStack;
7
import net.minecraft.network.RegistryFriendlyByteBuf;
8
import net.minecraft.network.codec.ByteBufCodecs;
9
import net.minecraft.network.codec.StreamCodec;
10
import net.minecraft.network.protocol.Packet;
11
import net.minecraft.network.protocol.PacketType;
12
import net.minecraft.world.inventory.ContainerInput;
13
14
public record ServerboundContainerClickPacket(
15
	int containerId, int stateId, short slotNum, byte buttonNum, ContainerInput containerInput, Int2ObjectMap<HashedStack> changedSlots, HashedStack carriedItem
16
) implements Packet<ServerGamePacketListener> {
17
	private static final int MAX_SLOT_COUNT = 128;
18
	private static final StreamCodec<RegistryFriendlyByteBuf, Int2ObjectMap<HashedStack>> SLOTS_STREAM_CODEC = ByteBufCodecs.map(
19
		Int2ObjectOpenHashMap::new, ByteBufCodecs.SHORT.map(Short::intValue, Integer::shortValue), HashedStack.STREAM_CODEC, 128
20
	);
21
	public static final StreamCodec<RegistryFriendlyByteBuf, ServerboundContainerClickPacket> STREAM_CODEC = StreamCodec.composite(
22
		ByteBufCodecs.CONTAINER_ID,
23
		ServerboundContainerClickPacket::containerId,
24
		ByteBufCodecs.VAR_INT,
25
		ServerboundContainerClickPacket::stateId,
26
		ByteBufCodecs.SHORT,
27
		ServerboundContainerClickPacket::slotNum,
28
		ByteBufCodecs.BYTE,
29
		ServerboundContainerClickPacket::buttonNum,
30
		ContainerInput.STREAM_CODEC,
31
		ServerboundContainerClickPacket::containerInput,
32
		SLOTS_STREAM_CODEC,
33
		ServerboundContainerClickPacket::changedSlots,
34
		HashedStack.STREAM_CODEC,
35
		ServerboundContainerClickPacket::carriedItem,
36
		ServerboundContainerClickPacket::new
37
	);
38
39
	public ServerboundContainerClickPacket {
40
		changedSlots = Int2ObjectMaps.unmodifiable(changedSlots);
41
	}
42
43
	@Override
44
	public PacketType<ServerboundContainerClickPacket> type() {
45
		return GamePacketTypes.SERVERBOUND_CONTAINER_CLICK;
46
	}
47
48
	public void handle(final ServerGamePacketListener listener) {
49
		listener.handleContainerClick(this);
50
	}
51
}
52