ClientboundAddTransientBlockPacket 0x25

ClientboundAddTransientBlockPacket: Minecraft 26.3 packet (0x25 Play clientbound). Wire name 'add_transient_block', fields: pos, blockState, handled

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x2537PLAYClientboundGamePacketTypes.CLIENTBOUND_ADD_TRANSIENT_BLOCK: "add_transient_block"

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

FieldType
posBlockPos
blockStateBlockState

Stream codec

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

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleAddTransientBlockPacket(ClientboundAddTransientBlockPacket clientboundaddtransientblockpacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundAddTransientBlockPacket.java51 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.RegistryFriendlyByteBuf;
5
import net.minecraft.network.codec.ByteBufCodecs;
6
import net.minecraft.network.codec.StreamCodec;
7
import net.minecraft.network.protocol.Packet;
8
import net.minecraft.network.protocol.PacketType;
9
import net.minecraft.world.level.block.Block;
10
import net.minecraft.world.level.block.state.BlockState;
11
12
public class ClientboundAddTransientBlockPacket implements Packet<ClientGamePacketListener> {
13
	public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundAddTransientBlockPacket> STREAM_CODEC = Packet.codec(
14
		ClientboundAddTransientBlockPacket::write, ClientboundAddTransientBlockPacket::new
15
	);
16
	private final BlockPos pos;
17
	private final BlockState blockState;
18
19
	public ClientboundAddTransientBlockPacket(final BlockPos pos, final BlockState blockState) {
20
		this.pos = pos;
21
		this.blockState = blockState;
22
	}
23
24
	public ClientboundAddTransientBlockPacket(final RegistryFriendlyByteBuf input) {
25
		this.pos = input.readBlockPos();
26
		this.blockState = ByteBufCodecs.idMapper(Block.BLOCK_STATE_REGISTRY).decode(input);
27
	}
28
29
	private void write(final RegistryFriendlyByteBuf output) {
30
		output.writeBlockPos(this.pos);
31
		ByteBufCodecs.idMapper(Block.BLOCK_STATE_REGISTRY).encode(output, this.blockState);
32
	}
33
34
	@Override
35
	public PacketType<ClientboundAddTransientBlockPacket> type() {
36
		return GamePacketTypes.CLIENTBOUND_ADD_TRANSIENT_BLOCK;
37
	}
38
39
	public void handle(final ClientGamePacketListener listener) {
40
		listener.handleAddTransientBlockPacket(this);
41
	}
42
43
	public BlockState getBlockState() {
44
		return this.blockState;
45
	}
46
47
	public BlockPos getPos() {
48
		return this.pos;
49
	}
50
}
51