ServerboundCommandSuggestionPacket 0x0F

ServerboundCommandSuggestionPacket: Minecraft 26.3 packet (0x0F Play serverbound). Wire name 'command_suggestion', fields: id, command, handled

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x0F15PLAYServerboundGamePacketTypes.SERVERBOUND_COMMAND_SUGGESTION: "command_suggestion"

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
idint
commandString

Fields are the components of the packet record.

Stream codec

static final StreamCodec<ByteBuf, ServerboundCommandSuggestionPacket> STREAM_CODEC = createStreamCodec(32500);

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleCustomCommandSuggestions(ServerboundCommandSuggestionPacket serverboundcommandsuggestionpacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundCommandSuggestionPacket.java48 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import io.netty.buffer.ByteBuf;
4
import io.netty.handler.codec.DecoderException;
5
import net.minecraft.network.SkipPacketDecoderException;
6
import net.minecraft.network.codec.ByteBufCodecs;
7
import net.minecraft.network.codec.StreamCodec;
8
import net.minecraft.network.protocol.Packet;
9
import net.minecraft.network.protocol.PacketType;
10
11
public record ServerboundCommandSuggestionPacket(int id, String command) implements Packet<ServerGamePacketListener> {
12
	public static final StreamCodec<ByteBuf, ServerboundCommandSuggestionPacket> STREAM_CODEC = createStreamCodec(32500);
13
	public static final StreamCodec<ByteBuf, ServerboundCommandSuggestionPacket> CHAT_ONLY_STREAM_CODEC = new StreamCodec<ByteBuf, ServerboundCommandSuggestionPacket>() {
14
		private final StreamCodec<ByteBuf, ServerboundCommandSuggestionPacket> downstream = ServerboundCommandSuggestionPacket.createStreamCodec(256);
15
16
		public ServerboundCommandSuggestionPacket decode(final ByteBuf input) {
17
			try {
18
				return this.downstream.decode(input);
19
			} catch (DecoderException e) {
20
				throw new SkipPacketDecoderException(e);
21
			}
22
		}
23
24
		public void encode(final ByteBuf output, final ServerboundCommandSuggestionPacket packet) {
25
			ServerboundCommandSuggestionPacket.STREAM_CODEC.encode(output, packet);
26
		}
27
	};
28
29
	private static StreamCodec<ByteBuf, ServerboundCommandSuggestionPacket> createStreamCodec(final int maxLength) {
30
		return StreamCodec.composite(
31
			ByteBufCodecs.VAR_INT,
32
			ServerboundCommandSuggestionPacket::id,
33
			ByteBufCodecs.stringUtf8(maxLength),
34
			ServerboundCommandSuggestionPacket::command,
35
			ServerboundCommandSuggestionPacket::new
36
		);
37
	}
38
39
	@Override
40
	public PacketType<ServerboundCommandSuggestionPacket> type() {
41
		return GamePacketTypes.SERVERBOUND_COMMAND_SUGGESTION;
42
	}
43
44
	public void handle(final ServerGamePacketListener listener) {
45
		listener.handleCustomCommandSuggestions(this);
46
	}
47
}
48