ClientboundBlockEntityDataPacket .java

net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket (class, 66 lines): members: getTag, tag, getPos, getType, create, handle, pos, type.

net.minecraft.network.protocol.gameclass66 linescommon2.3 KB

Implements

API Surface (7)

ClientboundBlockEntityDataPacket create(final BlockEntity blockEntity, final BiFunction<BlockEntity, RegistryAccess, CompoundTag> updateTagSaver)
ClientboundBlockEntityDataPacket create(final BlockEntity blockEntity)
PacketType<ClientboundBlockEntityDataPacket> type()
void handle(final ClientGamePacketListener listener)
BlockPos getPos()
BlockEntityType<?> getType()
CompoundTag getTag()

Fields & Constants (4)

STREAM_CODEC
pos
type
tag

Same Package (197)

Full Source

ClientboundBlockEntityDataPacket.java66 lines · Minecraft 26.3 · verbatim
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

Decompiled Minecraft 26.3 source of ClientboundBlockEntityDataPacket (net/minecraft/network/protocol/game/ClientboundBlockEntityDataPacket.java) with Mojang official mappings, stored verbatim on the site.