ClientboundLoginPacket 0x32

ClientboundLoginPacket: Minecraft 26.3 packet (0x32 Play clientbound). Wire name 'login', fields: playerId, hardcore, levels, maxPlayers, chunkRadius

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x3250PLAYClientboundGamePacketTypes.CLIENTBOUND_LOGIN: "login"

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

FieldType
playerIdint
hardcoreboolean
levelsSet<ResourceKey<Level>>
maxPlayersint
chunkRadiusint
simulationDistanceint
reducedDebugInfoboolean
showDeathScreenboolean
doLimitedCraftingboolean
commonPlayerSpawnInfoCommonPlayerSpawnInfo
onlineModeboolean
enforcesSecureChatboolean

Fields are the components of the packet record.

Stream codec

static final StreamCodec<RegistryFriendlyByteBuf, ClientboundLoginPacket> STREAM_CODEC = StreamCodec.composite( ByteBufCodecs.INT, ClientboundLoginPacket::playerId, ByteBufCodecs.BOOL, ClientboundLogi

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleLogin(ClientboundLoginPacket clientboundloginpacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundLoginPacket.java65 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import com.google.common.collect.Sets;
4
import java.util.Set;
5
import net.minecraft.core.registries.Registries;
6
import net.minecraft.network.RegistryFriendlyByteBuf;
7
import net.minecraft.network.codec.ByteBufCodecs;
8
import net.minecraft.network.codec.StreamCodec;
9
import net.minecraft.network.protocol.Packet;
10
import net.minecraft.network.protocol.PacketType;
11
import net.minecraft.resources.ResourceKey;
12
import net.minecraft.world.level.Level;
13
14
public record ClientboundLoginPacket(
15
	int playerId,
16
	boolean hardcore,
17
	Set<ResourceKey<Level>> levels,
18
	int maxPlayers,
19
	int chunkRadius,
20
	int simulationDistance,
21
	boolean reducedDebugInfo,
22
	boolean showDeathScreen,
23
	boolean doLimitedCrafting,
24
	CommonPlayerSpawnInfo commonPlayerSpawnInfo,
25
	boolean onlineMode,
26
	boolean enforcesSecureChat
27
) implements Packet<ClientGamePacketListener> {
28
	public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundLoginPacket> STREAM_CODEC = StreamCodec.composite(
29
		ByteBufCodecs.INT,
30
		ClientboundLoginPacket::playerId,
31
		ByteBufCodecs.BOOL,
32
		ClientboundLoginPacket::hardcore,
33
		ResourceKey.streamCodec(Registries.DIMENSION).apply(ByteBufCodecs.collection(Sets::newHashSetWithExpectedSize)),
34
		ClientboundLoginPacket::levels,
35
		ByteBufCodecs.VAR_INT,
36
		ClientboundLoginPacket::maxPlayers,
37
		ByteBufCodecs.VAR_INT,
38
		ClientboundLoginPacket::chunkRadius,
39
		ByteBufCodecs.VAR_INT,
40
		ClientboundLoginPacket::simulationDistance,
41
		ByteBufCodecs.BOOL,
42
		ClientboundLoginPacket::reducedDebugInfo,
43
		ByteBufCodecs.BOOL,
44
		ClientboundLoginPacket::showDeathScreen,
45
		ByteBufCodecs.BOOL,
46
		ClientboundLoginPacket::doLimitedCrafting,
47
		CommonPlayerSpawnInfo.STREAM_CODEC,
48
		ClientboundLoginPacket::commonPlayerSpawnInfo,
49
		ByteBufCodecs.BOOL,
50
		ClientboundLoginPacket::onlineMode,
51
		ByteBufCodecs.BOOL,
52
		ClientboundLoginPacket::enforcesSecureChat,
53
		ClientboundLoginPacket::new
54
	);
55
56
	@Override
57
	public PacketType<ClientboundLoginPacket> type() {
58
		return GamePacketTypes.CLIENTBOUND_LOGIN;
59
	}
60
61
	public void handle(final ClientGamePacketListener listener) {
62
		listener.handleLogin(this);
63
	}
64
}
65