ClientboundCustomQueryPacket 0x04

ClientboundCustomQueryPacket: Minecraft 26.3 packet (0x04 Login clientbound). Wire name 'custom_query', fields: transactionId, payload, handled

Minecraft 26.3LoginClientboundnet.minecraft.network.protocol.login

Protocol slots (1)

IDdecStateDirectionRegistry
0x044LOGINClientboundLoginPacketTypes.CLIENTBOUND_CUSTOM_QUERY: "custom_query"

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

FieldType
transactionIdint
payloadCustomQueryPayload

Fields are the components of the packet record.

Stream codec

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

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

Handling

Resolved on the ClientLoginPacketListener packet-listener interface by void handleCustomQuery(ClientboundCustomQueryPacket clientboundcustomquerypacket). The implementation in the game is ClientHandshakePacketListenerImpl.

Full Source

ClientboundCustomQueryPacket.java50 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.login;
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
import net.minecraft.network.protocol.login.custom.CustomQueryPayload;
8
import net.minecraft.network.protocol.login.custom.DiscardedQueryPayload;
9
import net.minecraft.resources.Identifier;
10
11
public record ClientboundCustomQueryPacket(int transactionId, CustomQueryPayload payload) implements Packet<ClientLoginPacketListener> {
12
	public static final StreamCodec<FriendlyByteBuf, ClientboundCustomQueryPacket> STREAM_CODEC = Packet.codec(
13
		ClientboundCustomQueryPacket::write, ClientboundCustomQueryPacket::new
14
	);
15
	private static final int MAX_PAYLOAD_SIZE = 1048576;
16
17
	private ClientboundCustomQueryPacket(final FriendlyByteBuf input) {
18
		this(input.readVarInt(), readPayload(input.readIdentifier(), input));
19
	}
20
21
	private static CustomQueryPayload readPayload(final Identifier identifier, final FriendlyByteBuf input) {
22
		return readUnknownPayload(identifier, input);
23
	}
24
25
	private static DiscardedQueryPayload readUnknownPayload(final Identifier identifier, final FriendlyByteBuf input) {
26
		int length = input.readableBytes();
27
		if (length >= 0 && length <= 1048576) {
28
			input.skipBytes(length);
29
			return new DiscardedQueryPayload(identifier);
30
		} else {
31
			throw new IllegalArgumentException("Payload may not be larger than 1048576 bytes");
32
		}
33
	}
34
35
	private void write(final FriendlyByteBuf output) {
36
		output.writeVarInt(this.transactionId);
37
		output.writeIdentifier(this.payload.id());
38
		this.payload.write(output);
39
	}
40
41
	@Override
42
	public PacketType<ClientboundCustomQueryPacket> type() {
43
		return LoginPacketTypes.CLIENTBOUND_CUSTOM_QUERY;
44
	}
45
46
	public void handle(final ClientLoginPacketListener listener) {
47
		listener.handleCustomQuery(this);
48
	}
49
}
50