ClientboundContainerSetSlotPacket 0x14

ClientboundContainerSetSlotPacket: Minecraft 26.3 packet (0x14 Play clientbound). Wire name 'container_set_slot', fields: containerId, stateId, slot

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x1420PLAYClientboundGamePacketTypes.CLIENTBOUND_CONTAINER_SET_SLOT: "container_set_slot"

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
containerIdint
stateIdint
slotint
itemStackItemStack

Stream codec

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

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleContainerSetSlot(ClientboundContainerSetSlotPacket clientboundcontainersetslotpacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundContainerSetSlotPacket.java64 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import net.minecraft.network.RegistryFriendlyByteBuf;
4
import net.minecraft.network.codec.StreamCodec;
5
import net.minecraft.network.protocol.Packet;
6
import net.minecraft.network.protocol.PacketType;
7
import net.minecraft.world.item.ItemStack;
8
9
public class ClientboundContainerSetSlotPacket implements Packet<ClientGamePacketListener> {
10
	public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundContainerSetSlotPacket> STREAM_CODEC = Packet.codec(
11
		ClientboundContainerSetSlotPacket::write, ClientboundContainerSetSlotPacket::new
12
	);
13
	private final int containerId;
14
	private final int stateId;
15
	private final int slot;
16
	private final ItemStack itemStack;
17
18
	public ClientboundContainerSetSlotPacket(final int containerId, final int stateId, final int slot, final ItemStack itemStack) {
19
		this.containerId = containerId;
20
		this.stateId = stateId;
21
		this.slot = slot;
22
		this.itemStack = itemStack.copy();
23
	}
24
25
	private ClientboundContainerSetSlotPacket(final RegistryFriendlyByteBuf input) {
26
		this.containerId = input.readContainerId();
27
		this.stateId = input.readVarInt();
28
		this.slot = input.readShort();
29
		this.itemStack = ItemStack.OPTIONAL_STREAM_CODEC.decode(input);
30
	}
31
32
	private void write(final RegistryFriendlyByteBuf output) {
33
		output.writeContainerId(this.containerId);
34
		output.writeVarInt(this.stateId);
35
		output.writeShort(this.slot);
36
		ItemStack.OPTIONAL_STREAM_CODEC.encode(output, this.itemStack);
37
	}
38
39
	@Override
40
	public PacketType<ClientboundContainerSetSlotPacket> type() {
41
		return GamePacketTypes.CLIENTBOUND_CONTAINER_SET_SLOT;
42
	}
43
44
	public void handle(final ClientGamePacketListener listener) {
45
		listener.handleContainerSetSlot(this);
46
	}
47
48
	public int getContainerId() {
49
		return this.containerId;
50
	}
51
52
	public int getSlot() {
53
		return this.slot;
54
	}
55
56
	public ItemStack getItem() {
57
		return this.itemStack;
58
	}
59
60
	public int getStateId() {
61
		return this.stateId;
62
	}
63
}
64