ServerboundCustomPayloadPacket 0x02

ServerboundCustomPayloadPacket: Minecraft 26.3 packet (0x02 Configuration serverbound, 0x16 Play serverbound).

Minecraft 26.3ConfigurationServerboundnet.minecraft.network.protocol.common

Protocol slots (2)

IDdecStateDirectionRegistry
0x022CONFIGURATIONServerboundCommonPacketTypes.SERVERBOUND_CUSTOM_PAYLOAD: "custom_payload"
0x1622PLAYServerboundCommonPacketTypes.SERVERBOUND_CUSTOM_PAYLOAD: "custom_payload"

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
payloadCustomPacketPayload

Fields are the components of the packet record.

Stream codec

static final StreamCodec<FriendlyByteBuf, ServerboundCustomPayloadPacket> STREAM_CODEC = CustomPacketPayload.<FriendlyByteBuf>codec( id -> DiscardedPayload.codec(id, 32767), Util.make(Lists.newArrayLi

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

Handling

Resolved on the ServerCommonPacketListener packet-listener interface by void handleCustomPayload(ServerboundCustomPayloadPacket serverboundcustompayloadpacket). The implementation in the game is ServerCommonPacketListenerImpl.

Full Source

ServerboundCustomPayloadPacket.java30 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.common;
2
3
import com.google.common.collect.Lists;
4
import net.minecraft.network.FriendlyByteBuf;
5
import net.minecraft.network.codec.StreamCodec;
6
import net.minecraft.network.protocol.Packet;
7
import net.minecraft.network.protocol.PacketType;
8
import net.minecraft.network.protocol.common.custom.BrandPayload;
9
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
10
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
11
import net.minecraft.util.Util;
12
13
public record ServerboundCustomPayloadPacket(CustomPacketPayload payload) implements Packet<ServerCommonPacketListener> {
14
	private static final int MAX_PAYLOAD_SIZE = 32767;
15
	public static final StreamCodec<FriendlyByteBuf, ServerboundCustomPayloadPacket> STREAM_CODEC = CustomPacketPayload.<FriendlyByteBuf>codec(
16
			id -> DiscardedPayload.codec(id, 32767),
17
			Util.make(Lists.newArrayList(new CustomPacketPayload.TypeAndCodec<>(BrandPayload.TYPE, BrandPayload.STREAM_CODEC)), types -> {})
18
		)
19
		.map(ServerboundCustomPayloadPacket::new, ServerboundCustomPayloadPacket::payload);
20
21
	@Override
22
	public PacketType<ServerboundCustomPayloadPacket> type() {
23
		return CommonPacketTypes.SERVERBOUND_CUSTOM_PAYLOAD;
24
	}
25
26
	public void handle(final ServerCommonPacketListener listener) {
27
		listener.handleCustomPayload(this);
28
	}
29
}
30