ClientboundBlockEntityDataPacket 0x06

ClientboundBlockEntityDataPacket: Minecraft 26.3 packet (0x06 Play clientbound). Wire name 'block_entity_data', handled

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x066PLAYClientboundGamePacketTypes.CLIENTBOUND_BLOCK_ENTITY_DATA: "block_entity_data"

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

FieldType
No wire fields (marker packet).

Stream codec

static final StreamCodec<RegistryFriendlyByteBuf, ClientboundBlockEntityDataPacket> STREAM_CODEC = StreamCodec.composite( BlockPos.STREAM_CODEC, ClientboundBlockEntityDataPacket::getPos, ByteBufCodecs

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleBlockEntityData(ClientboundBlockEntityDataPacket clientboundblockentitydatapacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundBlockEntityDataPacket.java66 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import java.util.function.BiFunction;
4
import net.minecraft.core.BlockPos;
5
import net.minecraft.core.RegistryAccess;
6
import net.minecraft.core.registries.Registries;
7
import net.minecraft.nbt.CompoundTag;
8
import net.minecraft.network.RegistryFriendlyByteBuf;
9
import net.minecraft.network.codec.ByteBufCodecs;
10
import net.minecraft.network.codec.StreamCodec;
11
import net.minecraft.network.protocol.Packet;
12
import net.minecraft.network.protocol.PacketType;
13
import net.minecraft.world.level.block.entity.BlockEntity;
14
import net.minecraft.world.level.block.entity.BlockEntityType;
15
16
public class ClientboundBlockEntityDataPacket implements Packet<ClientGamePacketListener> {
17
	public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundBlockEntityDataPacket> STREAM_CODEC = StreamCodec.composite(
18
		BlockPos.STREAM_CODEC,
19
		ClientboundBlockEntityDataPacket::getPos,
20
		ByteBufCodecs.registry(Registries.BLOCK_ENTITY_TYPE),
21
		ClientboundBlockEntityDataPacket::getType,
22
		ByteBufCodecs.TRUSTED_COMPOUND_TAG,
23
		ClientboundBlockEntityDataPacket::getTag,
24
		ClientboundBlockEntityDataPacket::new
25
	);
26
	private final BlockPos pos;
27
	private final BlockEntityType<?> type;
28
	private final CompoundTag tag;
29
30
	public static ClientboundBlockEntityDataPacket create(final BlockEntity blockEntity, final BiFunction<BlockEntity, RegistryAccess, CompoundTag> updateTagSaver) {
31
		RegistryAccess registryAccess = blockEntity.getLevel().registryAccess();
32
		return new ClientboundBlockEntityDataPacket(blockEntity.getBlockPos(), blockEntity.getType(), updateTagSaver.apply(blockEntity, registryAccess));
33
	}
34
35
	public static ClientboundBlockEntityDataPacket create(final BlockEntity blockEntity) {
36
		return create(blockEntity, BlockEntity::getUpdateTag);
37
	}
38
39
	private ClientboundBlockEntityDataPacket(final BlockPos pos, final BlockEntityType<?> type, final CompoundTag tag) {
40
		this.pos = pos;
41
		this.type = type;
42
		this.tag = tag;
43
	}
44
45
	@Override
46
	public PacketType<ClientboundBlockEntityDataPacket> type() {
47
		return GamePacketTypes.CLIENTBOUND_BLOCK_ENTITY_DATA;
48
	}
49
50
	public void handle(final ClientGamePacketListener listener) {
51
		listener.handleBlockEntityData(this);
52
	}
53
54
	public BlockPos getPos() {
55
		return this.pos;
56
	}
57
58
	public BlockEntityType<?> getType() {
59
		return this.type;
60
	}
61
62
	public CompoundTag getTag() {
63
		return this.tag;
64
	}
65
}
66