ClientboundBlockEventPacket 0x07

ClientboundBlockEventPacket: Minecraft 26.3 packet (0x07 Play clientbound). Wire name 'block_event', fields: pos, block, b0, b1, handled

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x077PLAYClientboundGamePacketTypes.CLIENTBOUND_BLOCK_EVENT: "block_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
posBlockPos
blockBlock
b0int
b1int

Stream codec

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

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleBlockEvent(ClientboundBlockEventPacket clientboundblockeventpacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundBlockEventPacket.java67 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.registries.Registries;
5
import net.minecraft.network.RegistryFriendlyByteBuf;
6
import net.minecraft.network.codec.ByteBufCodecs;
7
import net.minecraft.network.codec.StreamCodec;
8
import net.minecraft.network.protocol.Packet;
9
import net.minecraft.network.protocol.PacketType;
10
import net.minecraft.world.level.block.Block;
11
12
public class ClientboundBlockEventPacket implements Packet<ClientGamePacketListener> {
13
	public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundBlockEventPacket> STREAM_CODEC = Packet.codec(
14
		ClientboundBlockEventPacket::write, ClientboundBlockEventPacket::new
15
	);
16
	private final BlockPos pos;
17
	private final int b0;
18
	private final int b1;
19
	private final Block block;
20
21
	public ClientboundBlockEventPacket(final BlockPos pos, final Block block, final int b0, final int b1) {
22
		this.pos = pos;
23
		this.block = block;
24
		this.b0 = b0;
25
		this.b1 = b1;
26
	}
27
28
	private ClientboundBlockEventPacket(final RegistryFriendlyByteBuf input) {
29
		this.pos = input.readBlockPos();
30
		this.b0 = input.readUnsignedByte();
31
		this.b1 = input.readUnsignedByte();
32
		this.block = ByteBufCodecs.registry(Registries.BLOCK).decode(input);
33
	}
34
35
	private void write(final RegistryFriendlyByteBuf output) {
36
		output.writeBlockPos(this.pos);
37
		output.writeByte(this.b0);
38
		output.writeByte(this.b1);
39
		ByteBufCodecs.registry(Registries.BLOCK).encode(output, this.block);
40
	}
41
42
	@Override
43
	public PacketType<ClientboundBlockEventPacket> type() {
44
		return GamePacketTypes.CLIENTBOUND_BLOCK_EVENT;
45
	}
46
47
	public void handle(final ClientGamePacketListener listener) {
48
		listener.handleBlockEvent(this);
49
	}
50
51
	public BlockPos getPos() {
52
		return this.pos;
53
	}
54
55
	public int getB0() {
56
		return this.b0;
57
	}
58
59
	public int getB1() {
60
		return this.b1;
61
	}
62
63
	public Block getBlock() {
64
		return this.block;
65
	}
66
}
67