ServerboundCustomQueryAnswerPacket 0x02

ServerboundCustomQueryAnswerPacket: Minecraft 26.3 packet (0x02 Login serverbound). Wire name 'custom_query_answer', fields: transactionId, payload

Minecraft 26.3LoginServerboundnet.minecraft.network.protocol.login

Protocol slots (1)

IDdecStateDirectionRegistry
0x022LOGINServerboundLoginPacketTypes.SERVERBOUND_CUSTOM_QUERY_ANSWER: "custom_query_answer"

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
payload@Nullable CustomQueryAnswerPayload

Fields are the components of the packet record.

Stream codec

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

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

Handling

Resolved on the ServerLoginPacketListener packet-listener interface by void handleCustomQueryPacket(ServerboundCustomQueryAnswerPacket serverboundcustomqueryanswerpacket). The implementation in the game is ServerLoginPacketListenerImpl.

Full Source

ServerboundCustomQueryAnswerPacket.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.CustomQueryAnswerPayload;
8
import net.minecraft.network.protocol.login.custom.DiscardedQueryAnswerPayload;
9
import org.jspecify.annotations.Nullable;
10
11
public record ServerboundCustomQueryAnswerPacket(int transactionId, @Nullable CustomQueryAnswerPayload payload) implements Packet<ServerLoginPacketListener> {
12
	public static final StreamCodec<FriendlyByteBuf, ServerboundCustomQueryAnswerPacket> STREAM_CODEC = Packet.codec(
13
		ServerboundCustomQueryAnswerPacket::write, ServerboundCustomQueryAnswerPacket::read
14
	);
15
	private static final int MAX_PAYLOAD_SIZE = 1048576;
16
17
	private static ServerboundCustomQueryAnswerPacket read(final FriendlyByteBuf input) {
18
		int transactionId = input.readVarInt();
19
		return new ServerboundCustomQueryAnswerPacket(transactionId, readPayload(transactionId, input));
20
	}
21
22
	private static CustomQueryAnswerPayload readPayload(final int transactionId, final FriendlyByteBuf input) {
23
		return readUnknownPayload(input);
24
	}
25
26
	private static CustomQueryAnswerPayload readUnknownPayload(final FriendlyByteBuf input) {
27
		int length = input.readableBytes();
28
		if (length >= 0 && length <= 1048576) {
29
			input.skipBytes(length);
30
			return DiscardedQueryAnswerPayload.INSTANCE;
31
		} else {
32
			throw new IllegalArgumentException("Payload may not be larger than 1048576 bytes");
33
		}
34
	}
35
36
	private void write(final FriendlyByteBuf output) {
37
		output.writeVarInt(this.transactionId);
38
		output.writeNullable(this.payload, (buf, data) -> data.write(buf));
39
	}
40
41
	@Override
42
	public PacketType<ServerboundCustomQueryAnswerPacket> type() {
43
		return LoginPacketTypes.SERVERBOUND_CUSTOM_QUERY_ANSWER;
44
	}
45
46
	public void handle(final ServerLoginPacketListener listener) {
47
		listener.handleCustomQueryPacket(this);
48
	}
49
}
50