ClientboundRespawnPacket 0x54

ClientboundRespawnPacket: Minecraft 26.3 packet (0x54 Play clientbound). Wire name 'respawn', fields: commonPlayerSpawnInfo, dataToKeep, handled

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x5484PLAYClientboundGamePacketTypes.CLIENTBOUND_RESPAWN: "respawn"

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
commonPlayerSpawnInfoCommonPlayerSpawnInfo
dataToKeepbyte

Fields are the components of the packet record.

Stream codec

static final StreamCodec<RegistryFriendlyByteBuf, ClientboundRespawnPacket> STREAM_CODEC = StreamCodec.composite( CommonPlayerSpawnInfo.STREAM_CODEC, ClientboundRespawnPacket::commonPlayerSpawnInfo, B

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleRespawn(ClientboundRespawnPacket clientboundrespawnpacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundRespawnPacket.java34 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import net.minecraft.network.RegistryFriendlyByteBuf;
4
import net.minecraft.network.codec.ByteBufCodecs;
5
import net.minecraft.network.codec.StreamCodec;
6
import net.minecraft.network.protocol.Packet;
7
import net.minecraft.network.protocol.PacketType;
8
9
public record ClientboundRespawnPacket(CommonPlayerSpawnInfo commonPlayerSpawnInfo, byte dataToKeep) implements Packet<ClientGamePacketListener> {
10
	public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundRespawnPacket> STREAM_CODEC = StreamCodec.composite(
11
		CommonPlayerSpawnInfo.STREAM_CODEC,
12
		ClientboundRespawnPacket::commonPlayerSpawnInfo,
13
		ByteBufCodecs.BYTE,
14
		ClientboundRespawnPacket::dataToKeep,
15
		ClientboundRespawnPacket::new
16
	);
17
	public static final byte KEEP_ATTRIBUTE_MODIFIERS = 1;
18
	public static final byte KEEP_ENTITY_DATA = 2;
19
	public static final byte KEEP_ALL_DATA = 3;
20
21
	@Override
22
	public PacketType<ClientboundRespawnPacket> type() {
23
		return GamePacketTypes.CLIENTBOUND_RESPAWN;
24
	}
25
26
	public void handle(final ClientGamePacketListener listener) {
27
		listener.handleRespawn(this);
28
	}
29
30
	public boolean shouldKeep(final byte mask) {
31
		return (this.dataToKeep & mask) != 0;
32
	}
33
}
34