ServerboundTeleportToEntityPacket 0x40

ServerboundTeleportToEntityPacket: Minecraft 26.3 packet (0x40 Play serverbound). Wire name 'teleport_to_entity', fields: uuid, handled

Minecraft 26.3PlayServerboundnet.minecraft.network.protocol.game

Protocol slots (1)

IDdecStateDirectionRegistry
0x4064PLAYServerboundGamePacketTypes.SERVERBOUND_TELEPORT_TO_ENTITY: "teleport_to_entity"

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
uuidUUID

Stream codec

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

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

Handling

Resolved on the ServerGamePacketListener packet-listener interface by void handleTeleportToEntityPacket(ServerboundTeleportToEntityPacket serverboundteleporttoentitypacket). The implementation in the game is ServerGamePacketListenerImpl.

Full Source

ServerboundTeleportToEntityPacket.java43 lines · Minecraft 26.3 · verbatimSource page ↗
1
package net.minecraft.network.protocol.game;
2
3
import java.util.UUID;
4
import net.minecraft.network.FriendlyByteBuf;
5
import net.minecraft.network.codec.StreamCodec;
6
import net.minecraft.network.protocol.Packet;
7
import net.minecraft.network.protocol.PacketType;
8
import net.minecraft.server.level.ServerLevel;
9
import net.minecraft.world.entity.Entity;
10
import org.jspecify.annotations.Nullable;
11
12
public class ServerboundTeleportToEntityPacket implements Packet<ServerGamePacketListener> {
13
	public static final StreamCodec<FriendlyByteBuf, ServerboundTeleportToEntityPacket> STREAM_CODEC = Packet.codec(
14
		ServerboundTeleportToEntityPacket::write, ServerboundTeleportToEntityPacket::new
15
	);
16
	private final UUID uuid;
17
18
	public ServerboundTeleportToEntityPacket(final UUID uuid) {
19
		this.uuid = uuid;
20
	}
21
22
	private ServerboundTeleportToEntityPacket(final FriendlyByteBuf input) {
23
		this.uuid = input.readUUID();
24
	}
25
26
	private void write(final FriendlyByteBuf output) {
27
		output.writeUUID(this.uuid);
28
	}
29
30
	@Override
31
	public PacketType<ServerboundTeleportToEntityPacket> type() {
32
		return GamePacketTypes.SERVERBOUND_TELEPORT_TO_ENTITY;
33
	}
34
35
	public void handle(final ServerGamePacketListener listener) {
36
		listener.handleTeleportToEntityPacket(this);
37
	}
38
39
	public @Nullable Entity getEntity(final ServerLevel level) {
40
		return level.getEntity(this.uuid);
41
	}
42
}
43