ServerboundChatPacket 0x09

ServerboundChatPacket: Minecraft 26.3 packet (0x09 Play serverbound). Wire name 'chat', fields: message, timeStamp, salt, signature, lastSeenMessages

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x099PLAYServerboundGamePacketTypes.SERVERBOUND_CHAT: "chat"

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

FieldType
messageString
timeStampInstant
saltlong
signatureOptional<MessageSignature>
lastSeenMessagesLastSeenMessages.Update

Fields are the components of the packet record.

Stream codec

static final StreamCodec<FriendlyByteBuf, ServerboundChatPacket> STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.stringUtf8(256), ServerboundChatPacket::message, ByteBufCodecs.INSTANT, Serverbound

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleChat(ServerboundChatPacket serverboundchatpacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundChatPacket.java38 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import java.time.Instant;
4
import java.util.Optional;
5
import net.minecraft.network.FriendlyByteBuf;
6
import net.minecraft.network.chat.LastSeenMessages;
7
import net.minecraft.network.chat.MessageSignature;
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
13
public record ServerboundChatPacket(String message, Instant timeStamp, long salt, Optional<MessageSignature> signature, LastSeenMessages.Update lastSeenMessages)
14
	implements Packet<ServerGamePacketListener> {
15
	public static final StreamCodec<FriendlyByteBuf, ServerboundChatPacket> STREAM_CODEC = StreamCodec.composite(
16
		ByteBufCodecs.stringUtf8(256),
17
		ServerboundChatPacket::message,
18
		ByteBufCodecs.INSTANT,
19
		ServerboundChatPacket::timeStamp,
20
		ByteBufCodecs.LONG,
21
		ServerboundChatPacket::salt,
22
		MessageSignature.STREAM_CODEC.apply(ByteBufCodecs::optional),
23
		ServerboundChatPacket::signature,
24
		LastSeenMessages.Update.STREAM_CODEC,
25
		ServerboundChatPacket::lastSeenMessages,
26
		ServerboundChatPacket::new
27
	);
28
29
	@Override
30
	public PacketType<ServerboundChatPacket> type() {
31
		return GamePacketTypes.SERVERBOUND_CHAT;
32
	}
33
34
	public void handle(final ServerGamePacketListener listener) {
35
		listener.handleChat(this);
36
	}
37
}
38