ServerboundPlayerActionPacket 0x29

ServerboundPlayerActionPacket: Minecraft 26.3 packet (0x29 Play serverbound). Wire name 'player_action', fields: action, pos, direction, sequence, handled

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x2941PLAYServerboundGamePacketTypes.SERVERBOUND_PLAYER_ACTION: "player_action"

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

FieldType
actionServerboundPlayerActionPacket.Action
posBlockPos
directionDirection
sequenceint

Stream codec

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

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handlePlayerAction(ServerboundPlayerActionPacket serverboundplayeractionpacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundPlayerActionPacket.java81 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.core.Direction;
5
import net.minecraft.network.FriendlyByteBuf;
6
import net.minecraft.network.codec.StreamCodec;
7
import net.minecraft.network.protocol.Packet;
8
import net.minecraft.network.protocol.PacketType;
9
10
public class ServerboundPlayerActionPacket implements Packet<ServerGamePacketListener> {
11
	public static final StreamCodec<FriendlyByteBuf, ServerboundPlayerActionPacket> STREAM_CODEC = Packet.codec(
12
		ServerboundPlayerActionPacket::write, ServerboundPlayerActionPacket::new
13
	);
14
	private final BlockPos pos;
15
	private final Direction direction;
16
	private final ServerboundPlayerActionPacket.Action action;
17
	private final int sequence;
18
19
	public ServerboundPlayerActionPacket(final ServerboundPlayerActionPacket.Action action, final BlockPos pos, final Direction direction, final int sequence) {
20
		this.action = action;
21
		this.pos = pos.immutable();
22
		this.direction = direction;
23
		this.sequence = sequence;
24
	}
25
26
	public ServerboundPlayerActionPacket(final ServerboundPlayerActionPacket.Action action, final BlockPos pos, final Direction direction) {
27
		this(action, pos, direction, 0);
28
	}
29
30
	private ServerboundPlayerActionPacket(final FriendlyByteBuf input) {
31
		this.action = input.readEnum(ServerboundPlayerActionPacket.Action.class);
32
		this.pos = input.readBlockPos();
33
		this.direction = Direction.from3DDataValue(input.readUnsignedByte());
34
		this.sequence = input.readVarInt();
35
	}
36
37
	private void write(final FriendlyByteBuf output) {
38
		output.writeEnum(this.action);
39
		output.writeBlockPos(this.pos);
40
		output.writeByte(this.direction.get3DDataValue());
41
		output.writeVarInt(this.sequence);
42
	}
43
44
	@Override
45
	public PacketType<ServerboundPlayerActionPacket> type() {
46
		return GamePacketTypes.SERVERBOUND_PLAYER_ACTION;
47
	}
48
49
	public void handle(final ServerGamePacketListener listener) {
50
		listener.handlePlayerAction(this);
51
	}
52
53
	public BlockPos getPos() {
54
		return this.pos;
55
	}
56
57
	public Direction getDirection() {
58
		return this.direction;
59
	}
60
61
	public ServerboundPlayerActionPacket.Action getAction() {
62
		return this.action;
63
	}
64
65
	public int getSequence() {
66
		return this.sequence;
67
	}
68
69
	public enum Action {
70
		START_DESTROY_BLOCK,
71
		CHANGE_DESTROY_DIRECTION,
72
		ABORT_DESTROY_BLOCK,
73
		STOP_DESTROY_BLOCK,
74
		DROP_ALL_ITEMS,
75
		DROP_ITEM,
76
		RELEASE_USE_ITEM,
77
		SWAP_ITEM_WITH_OFFHAND,
78
		STAB;
79
	}
80
}
81