ClientboundSetEntityDataPacket 0x65

ClientboundSetEntityDataPacket: Minecraft 26.3 packet (0x65 Play clientbound). Wire name 'set_entity_data', fields: id, packedItems, handled

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x65101PLAYClientboundGamePacketTypes.CLIENTBOUND_SET_ENTITY_DATA: "set_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 (2)

FieldType
idint
packedItemsList<SynchedEntityData.DataValue<?>>

Fields are the components of the packet record.

Stream codec

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

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleSetEntityData(ClientboundSetEntityDataPacket clientboundsetentitydatapacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundSetEntityDataPacket.java54 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import java.util.ArrayList;
4
import java.util.List;
5
import net.minecraft.network.RegistryFriendlyByteBuf;
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.network.syncher.SynchedEntityData;
10
11
public record ClientboundSetEntityDataPacket(int id, List<SynchedEntityData.DataValue<?>> packedItems) implements Packet<ClientGamePacketListener> {
12
	public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundSetEntityDataPacket> STREAM_CODEC = Packet.codec(
13
		ClientboundSetEntityDataPacket::write, ClientboundSetEntityDataPacket::new
14
	);
15
	public static final int EOF_MARKER = 255;
16
17
	private ClientboundSetEntityDataPacket(final RegistryFriendlyByteBuf input) {
18
		this(input.readVarInt(), unpack(input));
19
	}
20
21
	private static void pack(final List<SynchedEntityData.DataValue<?>> items, final RegistryFriendlyByteBuf output) {
22
		for (SynchedEntityData.DataValue<?> item : items) {
23
			item.write(output);
24
		}
25
26
		output.writeByte(255);
27
	}
28
29
	private static List<SynchedEntityData.DataValue<?>> unpack(final RegistryFriendlyByteBuf input) {
30
		List<SynchedEntityData.DataValue<?>> result = new ArrayList<>();
31
32
		int id;
33
		while ((id = input.readUnsignedByte()) != 255) {
34
			result.add(SynchedEntityData.DataValue.read(input, id));
35
		}
36
37
		return result;
38
	}
39
40
	private void write(final RegistryFriendlyByteBuf output) {
41
		output.writeVarInt(this.id);
42
		pack(this.packedItems, output);
43
	}
44
45
	@Override
46
	public PacketType<ClientboundSetEntityDataPacket> type() {
47
		return GamePacketTypes.CLIENTBOUND_SET_ENTITY_DATA;
48
	}
49
50
	public void handle(final ClientGamePacketListener listener) {
51
		listener.handleSetEntityData(this);
52
	}
53
}
54