ClientboundBlockDestructionPacket 0x05

ClientboundBlockDestructionPacket: Minecraft 26.3 packet (0x05 Play clientbound). Wire name 'block_destruction', fields: id, pos, progress, handled

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x055PLAYClientboundGamePacketTypes.CLIENTBOUND_BLOCK_DESTRUCTION: "block_destruction"

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

FieldType
idint
posBlockPos
progressint

Stream codec

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

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleBlockDestruction(ClientboundBlockDestructionPacket clientboundblockdestructionpacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundBlockDestructionPacket.java56 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
9
public class ClientboundBlockDestructionPacket implements Packet<ClientGamePacketListener> {
10
	public static final StreamCodec<FriendlyByteBuf, ClientboundBlockDestructionPacket> STREAM_CODEC = Packet.codec(
11
		ClientboundBlockDestructionPacket::write, ClientboundBlockDestructionPacket::new
12
	);
13
	private final int id;
14
	private final BlockPos pos;
15
	private final int progress;
16
17
	public ClientboundBlockDestructionPacket(final int id, final BlockPos pos, final int progress) {
18
		this.id = id;
19
		this.pos = pos;
20
		this.progress = progress;
21
	}
22
23
	private ClientboundBlockDestructionPacket(final FriendlyByteBuf input) {
24
		this.id = input.readVarInt();
25
		this.pos = input.readBlockPos();
26
		this.progress = input.readUnsignedByte();
27
	}
28
29
	private void write(final FriendlyByteBuf output) {
30
		output.writeVarInt(this.id);
31
		output.writeBlockPos(this.pos);
32
		output.writeByte(this.progress);
33
	}
34
35
	@Override
36
	public PacketType<ClientboundBlockDestructionPacket> type() {
37
		return GamePacketTypes.CLIENTBOUND_BLOCK_DESTRUCTION;
38
	}
39
40
	public void handle(final ClientGamePacketListener listener) {
41
		listener.handleBlockDestruction(this);
42
	}
43
44
	public int getId() {
45
		return this.id;
46
	}
47
48
	public BlockPos getPos() {
49
		return this.pos;
50
	}
51
52
	public int getProgress() {
53
		return this.progress;
54
	}
55
}
56