ClientboundContainerSetContentPacket 0x12

ClientboundContainerSetContentPacket: Minecraft 26.3 packet (0x12 Play clientbound). Wire name 'container_set_content', fields: containerId, stateId

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x1218PLAYClientboundGamePacketTypes.CLIENTBOUND_CONTAINER_SET_CONTENT: "container_set_content"

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
itemsList<ItemStack>
carriedItemItemStack

Fields are the components of the packet record.

Stream codec

static final StreamCodec<RegistryFriendlyByteBuf, ClientboundContainerSetContentPacket> STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.CONTAINER_ID, ClientboundContainerSetContentPacket::containe

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleContainerContent(ClientboundContainerSetContentPacket clientboundcontainersetcontentpacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundContainerSetContentPacket.java34 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import java.util.List;
4
import net.minecraft.network.RegistryFriendlyByteBuf;
5
import net.minecraft.network.codec.ByteBufCodecs;
6
import net.minecraft.network.codec.StreamCodec;
7
import net.minecraft.network.protocol.Packet;
8
import net.minecraft.network.protocol.PacketType;
9
import net.minecraft.world.item.ItemStack;
10
11
public record ClientboundContainerSetContentPacket(int containerId, int stateId, List<ItemStack> items, ItemStack carriedItem)
12
	implements Packet<ClientGamePacketListener> {
13
	public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundContainerSetContentPacket> STREAM_CODEC = StreamCodec.composite(
14
		ByteBufCodecs.CONTAINER_ID,
15
		ClientboundContainerSetContentPacket::containerId,
16
		ByteBufCodecs.VAR_INT,
17
		ClientboundContainerSetContentPacket::stateId,
18
		ItemStack.OPTIONAL_LIST_STREAM_CODEC,
19
		ClientboundContainerSetContentPacket::items,
20
		ItemStack.OPTIONAL_STREAM_CODEC,
21
		ClientboundContainerSetContentPacket::carriedItem,
22
		ClientboundContainerSetContentPacket::new
23
	);
24
25
	@Override
26
	public PacketType<ClientboundContainerSetContentPacket> type() {
27
		return GamePacketTypes.CLIENTBOUND_CONTAINER_SET_CONTENT;
28
	}
29
30
	public void handle(final ClientGamePacketListener listener) {
31
		listener.handleContainerContent(this);
32
	}
33
}
34