ServerboundChatCommandPacket 0x07

ServerboundChatCommandPacket: Minecraft 26.3 packet (0x07 Play serverbound). Wire name 'chat_command', fields: command, handled

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x077PLAYServerboundGamePacketTypes.SERVERBOUND_CHAT_COMMAND: "chat_command"

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

FieldType
commandString

Fields are the components of the packet record.

Stream codec

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

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleChatCommand(ServerboundChatCommandPacket serverboundchatcommandpacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundChatCommandPacket.java30 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 ServerboundChatCommandPacket(String command) implements Packet<ServerGamePacketListener> {
9
	public static final StreamCodec<FriendlyByteBuf, ServerboundChatCommandPacket> STREAM_CODEC = Packet.codec(
10
		ServerboundChatCommandPacket::write, ServerboundChatCommandPacket::new
11
	);
12
13
	private ServerboundChatCommandPacket(final FriendlyByteBuf input) {
14
		this(input.readUtf());
15
	}
16
17
	private void write(final FriendlyByteBuf output) {
18
		output.writeUtf(this.command);
19
	}
20
21
	@Override
22
	public PacketType<ServerboundChatCommandPacket> type() {
23
		return GamePacketTypes.SERVERBOUND_CHAT_COMMAND;
24
	}
25
26
	public void handle(final ServerGamePacketListener listener) {
27
		listener.handleChatCommand(this);
28
	}
29
}
30