ServerboundKeepAlivePacket 0x04

ServerboundKeepAlivePacket: Minecraft 26.3 packet (0x04 Configuration serverbound, 0x1C Play serverbound).

Minecraft 26.3ConfigurationServerboundnet.minecraft.network.protocol.common

Protocol slots (2)

IDdecStateDirectionRegistry
0x044CONFIGURATIONServerboundCommonPacketTypes.SERVERBOUND_KEEP_ALIVE: "keep_alive"
0x1C28PLAYServerboundCommonPacketTypes.SERVERBOUND_KEEP_ALIVE: "keep_alive"

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
idlong

Stream codec

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

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

Handling

Resolved on the ServerCommonPacketListener packet-listener interface by void handleKeepAlive(ServerboundKeepAlivePacket serverboundkeepalivepacket). The implementation in the game is ServerCommonPacketListenerImpl.

Full Source

ServerboundKeepAlivePacket.java39 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.common;
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
8
public class ServerboundKeepAlivePacket implements Packet<ServerCommonPacketListener> {
9
	public static final StreamCodec<FriendlyByteBuf, ServerboundKeepAlivePacket> STREAM_CODEC = Packet.codec(
10
		ServerboundKeepAlivePacket::write, ServerboundKeepAlivePacket::new
11
	);
12
	private final long id;
13
14
	public ServerboundKeepAlivePacket(final long id) {
15
		this.id = id;
16
	}
17
18
	private ServerboundKeepAlivePacket(final FriendlyByteBuf input) {
19
		this.id = input.readLong();
20
	}
21
22
	private void write(final FriendlyByteBuf output) {
23
		output.writeLong(this.id);
24
	}
25
26
	@Override
27
	public PacketType<ServerboundKeepAlivePacket> type() {
28
		return CommonPacketTypes.SERVERBOUND_KEEP_ALIVE;
29
	}
30
31
	public void handle(final ServerCommonPacketListener listener) {
32
		listener.handleKeepAlive(this);
33
	}
34
35
	public long getId() {
36
		return this.id;
37
	}
38
}
39