ClientboundPlayerChatPacket 0x42

ClientboundPlayerChatPacket: Minecraft 26.3 packet (0x42 Play clientbound). Wire name 'player_chat', fields: globalIndex, sender, index, signature, body

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x4266PLAYClientboundGamePacketTypes.CLIENTBOUND_PLAYER_CHAT: "player_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 (8)

FieldType
globalIndexint
senderUUID
indexint
signatureOptional<MessageSignature>
bodySignedMessageBody.Packed
unsignedContentOptional<Component>
filterMaskFilterMask
chatTypeChatType.Bound

Fields are the components of the packet record.

Stream codec

static final StreamCodec<RegistryFriendlyByteBuf, ClientboundPlayerChatPacket> STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.VAR_INT, ClientboundPlayerChatPacket::globalIndex, UUIDUtil.STREAM_CO

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handlePlayerChat(ClientboundPlayerChatPacket clientboundplayerchatpacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundPlayerChatPacket.java62 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import java.util.Optional;
4
import java.util.UUID;
5
import net.minecraft.core.UUIDUtil;
6
import net.minecraft.network.RegistryFriendlyByteBuf;
7
import net.minecraft.network.chat.ChatType;
8
import net.minecraft.network.chat.Component;
9
import net.minecraft.network.chat.ComponentSerialization;
10
import net.minecraft.network.chat.FilterMask;
11
import net.minecraft.network.chat.MessageSignature;
12
import net.minecraft.network.chat.SignedMessageBody;
13
import net.minecraft.network.codec.ByteBufCodecs;
14
import net.minecraft.network.codec.StreamCodec;
15
import net.minecraft.network.protocol.Packet;
16
import net.minecraft.network.protocol.PacketType;
17
18
public record ClientboundPlayerChatPacket(
19
	int globalIndex,
20
	UUID sender,
21
	int index,
22
	Optional<MessageSignature> signature,
23
	SignedMessageBody.Packed body,
24
	Optional<Component> unsignedContent,
25
	FilterMask filterMask,
26
	ChatType.Bound chatType
27
) implements Packet<ClientGamePacketListener> {
28
	public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundPlayerChatPacket> STREAM_CODEC = StreamCodec.composite(
29
		ByteBufCodecs.VAR_INT,
30
		ClientboundPlayerChatPacket::globalIndex,
31
		UUIDUtil.STREAM_CODEC,
32
		ClientboundPlayerChatPacket::sender,
33
		ByteBufCodecs.VAR_INT,
34
		ClientboundPlayerChatPacket::index,
35
		MessageSignature.STREAM_CODEC.apply(ByteBufCodecs::optional),
36
		ClientboundPlayerChatPacket::signature,
37
		SignedMessageBody.Packed.STREAM_CODEC,
38
		ClientboundPlayerChatPacket::body,
39
		ComponentSerialization.TRUSTED_OPTIONAL_STREAM_CODEC,
40
		ClientboundPlayerChatPacket::unsignedContent,
41
		FilterMask.STREAM_CODEC,
42
		ClientboundPlayerChatPacket::filterMask,
43
		ChatType.Bound.STREAM_CODEC,
44
		ClientboundPlayerChatPacket::chatType,
45
		ClientboundPlayerChatPacket::new
46
	);
47
48
	@Override
49
	public PacketType<ClientboundPlayerChatPacket> type() {
50
		return GamePacketTypes.CLIENTBOUND_PLAYER_CHAT;
51
	}
52
53
	public void handle(final ClientGamePacketListener listener) {
54
		listener.handlePlayerChat(this);
55
	}
56
57
	@Override
58
	public boolean isSkippable() {
59
		return true;
60
	}
61
}
62