ClientboundLevelEventPacket 0x2F

ClientboundLevelEventPacket: Minecraft 26.3 packet (0x2F Play clientbound). Wire name 'level_event', fields: type, pos, data, globalEvent, handled

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x2F47PLAYClientboundGamePacketTypes.CLIENTBOUND_LEVEL_EVENT: "level_event"

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
type@LevelEvent.Value int
posBlockPos
dataint
globalEventboolean

Stream codec

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

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleLevelEvent(ClientboundLevelEventPacket clientboundleveleventpacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundLevelEventPacket.java65 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import net.minecraft.core.BlockPos;
4
import net.minecraft.network.FriendlyByteBuf;
5
import net.minecraft.network.codec.StreamCodec;
6
import net.minecraft.network.protocol.Packet;
7
import net.minecraft.network.protocol.PacketType;
8
import net.minecraft.world.level.block.LevelEvent;
9
10
public class ClientboundLevelEventPacket implements Packet<ClientGamePacketListener> {
11
	public static final StreamCodec<FriendlyByteBuf, ClientboundLevelEventPacket> STREAM_CODEC = Packet.codec(
12
		ClientboundLevelEventPacket::write, ClientboundLevelEventPacket::new
13
	);
14
	private final @LevelEvent.Value int type;
15
	private final BlockPos pos;
16
	private final int data;
17
	private final boolean globalEvent;
18
19
	public ClientboundLevelEventPacket(final @LevelEvent.Value int type, final BlockPos pos, final int data, final boolean globalEvent) {
20
		this.type = type;
21
		this.pos = pos.immutable();
22
		this.data = data;
23
		this.globalEvent = globalEvent;
24
	}
25
26
	private ClientboundLevelEventPacket(final FriendlyByteBuf input) {
27
		this.type = input.readInt();
28
		this.pos = input.readBlockPos();
29
		this.data = input.readInt();
30
		this.globalEvent = input.readBoolean();
31
	}
32
33
	private void write(final FriendlyByteBuf output) {
34
		output.writeInt(this.type);
35
		output.writeBlockPos(this.pos);
36
		output.writeInt(this.data);
37
		output.writeBoolean(this.globalEvent);
38
	}
39
40
	@Override
41
	public PacketType<ClientboundLevelEventPacket> type() {
42
		return GamePacketTypes.CLIENTBOUND_LEVEL_EVENT;
43
	}
44
45
	public void handle(final ClientGamePacketListener listener) {
46
		listener.handleLevelEvent(this);
47
	}
48
49
	public boolean isGlobalEvent() {
50
		return this.globalEvent;
51
	}
52
53
	public @LevelEvent.Value int getType() {
54
		return this.type;
55
	}
56
57
	public int getData() {
58
		return this.data;
59
	}
60
61
	public BlockPos getPos() {
62
		return this.pos;
63
	}
64
}
65