ClientboundOpenScreenPacket 0x3C

ClientboundOpenScreenPacket: Minecraft 26.3 packet (0x3C Play clientbound). Wire name 'open_screen', fields: containerId, type, title, handled

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x3C60PLAYClientboundGamePacketTypes.CLIENTBOUND_OPEN_SCREEN: "open_screen"

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

FieldType
containerIdint
typeMenuType<?>
titleComponent

Stream codec

static final StreamCodec<RegistryFriendlyByteBuf, ClientboundOpenScreenPacket> STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.CONTAINER_ID, ClientboundOpenScreenPacket::getContainerId, ByteBufCod

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleOpenScreen(ClientboundOpenScreenPacket clientboundopenscreenpacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundOpenScreenPacket.java54 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import net.minecraft.core.registries.Registries;
4
import net.minecraft.network.RegistryFriendlyByteBuf;
5
import net.minecraft.network.chat.Component;
6
import net.minecraft.network.chat.ComponentSerialization;
7
import net.minecraft.network.codec.ByteBufCodecs;
8
import net.minecraft.network.codec.StreamCodec;
9
import net.minecraft.network.protocol.Packet;
10
import net.minecraft.network.protocol.PacketType;
11
import net.minecraft.world.inventory.MenuType;
12
13
public class ClientboundOpenScreenPacket implements Packet<ClientGamePacketListener> {
14
	public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundOpenScreenPacket> STREAM_CODEC = StreamCodec.composite(
15
		ByteBufCodecs.CONTAINER_ID,
16
		ClientboundOpenScreenPacket::getContainerId,
17
		ByteBufCodecs.registry(Registries.MENU),
18
		ClientboundOpenScreenPacket::getType,
19
		ComponentSerialization.TRUSTED_STREAM_CODEC,
20
		ClientboundOpenScreenPacket::getTitle,
21
		ClientboundOpenScreenPacket::new
22
	);
23
	private final int containerId;
24
	private final MenuType<?> type;
25
	private final Component title;
26
27
	public ClientboundOpenScreenPacket(final int containerId, final MenuType<?> type, final Component title) {
28
		this.containerId = containerId;
29
		this.type = type;
30
		this.title = title;
31
	}
32
33
	@Override
34
	public PacketType<ClientboundOpenScreenPacket> type() {
35
		return GamePacketTypes.CLIENTBOUND_OPEN_SCREEN;
36
	}
37
38
	public void handle(final ClientGamePacketListener listener) {
39
		listener.handleOpenScreen(this);
40
	}
41
42
	public int getContainerId() {
43
		return this.containerId;
44
	}
45
46
	public MenuType<?> getType() {
47
		return this.type;
48
	}
49
50
	public Component getTitle() {
51
		return this.title;
52
	}
53
}
54