ServerboundPlayerAbilitiesPacket 0x28

ServerboundPlayerAbilitiesPacket: Minecraft 26.3 packet (0x28 Play serverbound). Wire name 'player_abilities', fields: abilities, handled

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x2840PLAYServerboundGamePacketTypes.SERVERBOUND_PLAYER_ABILITIES: "player_abilities"

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
abilitiesAbilities

Stream codec

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

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket serverboundplayerabilitiespacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundPlayerAbilitiesPacket.java47 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
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.world.entity.player.Abilities;
8
9
public class ServerboundPlayerAbilitiesPacket implements Packet<ServerGamePacketListener> {
10
	public static final StreamCodec<FriendlyByteBuf, ServerboundPlayerAbilitiesPacket> STREAM_CODEC = Packet.codec(
11
		ServerboundPlayerAbilitiesPacket::write, ServerboundPlayerAbilitiesPacket::new
12
	);
13
	private static final int FLAG_FLYING = 2;
14
	private final boolean isFlying;
15
16
	public ServerboundPlayerAbilitiesPacket(final Abilities abilities) {
17
		this.isFlying = abilities.flying;
18
	}
19
20
	private ServerboundPlayerAbilitiesPacket(final FriendlyByteBuf input) {
21
		byte bitfield = input.readByte();
22
		this.isFlying = (bitfield & 2) != 0;
23
	}
24
25
	private void write(final FriendlyByteBuf output) {
26
		byte bitfield = 0;
27
		if (this.isFlying) {
28
			bitfield = (byte)(bitfield | 2);
29
		}
30
31
		output.writeByte(bitfield);
32
	}
33
34
	@Override
35
	public PacketType<ServerboundPlayerAbilitiesPacket> type() {
36
		return GamePacketTypes.SERVERBOUND_PLAYER_ABILITIES;
37
	}
38
39
	public void handle(final ServerGamePacketListener listener) {
40
		listener.handlePlayerAbilities(this);
41
	}
42
43
	public boolean isFlying() {
44
		return this.isFlying;
45
	}
46
}
47