ClientboundSetCameraPacket 0x5F

ClientboundSetCameraPacket: Minecraft 26.3 packet (0x5F Play clientbound). Wire name 'set_camera', fields: camera, handled

Minecraft 26.3PlayClientboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x5F95PLAYClientboundGamePacketTypes.CLIENTBOUND_SET_CAMERA: "set_camera"

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

FieldType
cameraEntity

Stream codec

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

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

Handling

Resolved on the ClientGamePacketListener packet-listener interface by void handleSetCamera(ClientboundSetCameraPacket clientboundsetcamerapacket). The implementation in the game is ClientPacketListener.

Full Source

ClientboundSetCameraPacket.java42 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import net.minecraft.network.FriendlyByteBuf;
4
import net.minecraft.network.codec.StreamCodec;
5
import net.minecraft.network.protocol.Packet;
6
import net.minecraft.network.protocol.PacketType;
7
import net.minecraft.world.entity.Entity;
8
import net.minecraft.world.level.Level;
9
import org.jspecify.annotations.Nullable;
10
11
public class ClientboundSetCameraPacket implements Packet<ClientGamePacketListener> {
12
	public static final StreamCodec<FriendlyByteBuf, ClientboundSetCameraPacket> STREAM_CODEC = Packet.codec(
13
		ClientboundSetCameraPacket::write, ClientboundSetCameraPacket::new
14
	);
15
	private final int cameraId;
16
17
	public ClientboundSetCameraPacket(final Entity camera) {
18
		this.cameraId = camera.getId();
19
	}
20
21
	private ClientboundSetCameraPacket(final FriendlyByteBuf input) {
22
		this.cameraId = input.readVarInt();
23
	}
24
25
	private void write(final FriendlyByteBuf output) {
26
		output.writeVarInt(this.cameraId);
27
	}
28
29
	@Override
30
	public PacketType<ClientboundSetCameraPacket> type() {
31
		return GamePacketTypes.CLIENTBOUND_SET_CAMERA;
32
	}
33
34
	public void handle(final ClientGamePacketListener listener) {
35
		listener.handleSetCamera(this);
36
	}
37
38
	public @Nullable Entity getEntity(final Level level) {
39
		return level.getEntity(this.cameraId);
40
	}
41
}
42