Skip to content

1.21.x Entity Teleport packet has errors #3609

Description

@kenshineto

Make sure you're doing the following

  • You're using the latest build for your server version
  • This isn't an issue caused by another plugin
  • You've checked for duplicate issues
  • You didn't use /reload

Describe the question
I am working on updating my plugin to support the 1.21.x series of releases (and soon 26.1)
My server is on paper 1.21.11 build 127
I am using the latest dev build of protocol lib (v5.5.0-SNAPSHOT-f911ee9)

I have tested by plugin against both protocol lib 5.4.0 from maven, and v5.5.0-SNAPSHOT-f911ee9 directly from the jar

I am trying to create an ENTITY_TELEPORT (or on new versions after 1.21.2, ENTITY_POSITION_SYNC) packet

When I try to set the position (there are three doubles, x, y ,z) as described for both packets in the protocol wiki, i get the following error

[09:21:22 WARN]: [KenshinsHideAndSeek] Task #3 for KenshinsHideAndSeek v2.0.0 generated an exception
com.comphenix.protocol.reflect.FieldAccessException: Field index 0 is out of bounds for length 0
	at ProtocolLib.jar//com.comphenix.protocol.reflect.FieldAccessException.fromFormat(FieldAccessException.java:49) ~[?:?]
	at ProtocolLib.jar//com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:318) ~[?:?]
	at khs-2.0.0-SNAPSHOT.jar//cat.freya.khs.bukkit.packet.EntityTeleportPacket.setPosition(EntityTeleportPacket.kt:21) ~[?:?]
	at khs-2.0.0-SNAPSHOT.jar//cat.freya.khs.bukkit.disguise.Disguise.teleportEntity(Disguise.kt:163) ~[?:?]
	at khs-2.0.0-SNAPSHOT.jar//cat.freya.khs.bukkit.disguise.Disguise.update(Disguise.kt:78) ~[?:?]
	at khs-2.0.0-SNAPSHOT.jar//cat.freya.khs.bukkit.disguise.Disguiser.update(Disguiser.kt:46) ~[?:?]
	at khs-2.0.0-SNAPSHOT.jar//cat.freya.khs.bukkit.KhsPlugin$onEnable$1.run(Plugin.kt:30) ~[?:?]
	at org.bukkit.craftbukkit.scheduler.CraftTask.run(CraftTask.java:78) ~[paper-1.21.11.jar:1.21.11-127-bd74bf6]
	at org.bukkit.craftbukkit.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:474) ~[paper-1.21.11.jar:1.21.11-127-bd74bf6]
	at net.minecraft.server.MinecraftServer.tickChildren(MinecraftServer.java:1756) ~[paper-1.21.11.jar:1.21.11-127-bd74bf6]
	at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1611) ~[paper-1.21.11.jar:1.21.11-127-bd74bf6]
	at net.minecraft.server.dedicated.DedicatedServer.tickServer(DedicatedServer.java:427) ~[paper-1.21.11.jar:1.21.11-127-bd74bf6]
	at net.minecraft.server.MinecraftServer.processPacketsAndTick(MinecraftServer.java:1667) ~[paper-1.21.11.jar:1.21.11-127-bd74bf6]
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1335) ~[paper-1.21.11.jar:1.21.11-127-bd74bf6]
	at net.minecraft.server.MinecraftServer.lambda$spin$2(MinecraftServer.java:388) ~[paper-1.21.11.jar:1.21.11-127-bd74bf6]
	at java.base/java.lang.Thread.run(Thread.java:1474) ~[?:?]

A clear and concise description of what your question is.

API method(s) used

This is the following code I use. Note this is kotlin, so things like .doubles is aliased from .getDoubles()

abstract class Packet(val type: PacketType) {
    val manager: ProtocolManager
    val packet: PacketContainer

    init {
        manager = ProtocolLibrary.getProtocolManager()
        packet = manager.createPacket(type)
        packet.modifier.writeDefaults()
    }

    fun send(player: BukkitPlayer) {
        manager.sendServerPacket(player, packet)
    }

    fun send(player: KhsPlayer) { // inner is org.bukkit.entity.Player
        send((player as BukkitKhsPlayer).inner)
    }
}

private fun getPacketType(plugin: KhsPlugin): PacketType {
    if (plugin.shim.supports(21, 2))
        return PacketType.Play.Server.ENTITY_POSITION_SYNC
    else
        return PacketType.Play.Server.ENTITY_TELEPORT
}

class EntityTeleportPacket(val plugin: KhsPlugin) : Packet(getPacketType(plugin)) {

    fun setEntity(entity: Entity) {
        packet.integers.write(0, entity.entityId)
    }

    fun setPosition(x: Double, y: Double, z: Double) {
        packet.doubles.write(0, x)
        packet.doubles.write(0, y)
        packet.doubles.write(0, z)
    }
}

Expected behavior

On previous versions 1.20.x and before this worked fine, but now its not. I'm making this issue as an api question as I don't know for sure if its a bug on protocol libs end, and more likely my skill issue (but who knows)

Am I doing anything wrong or is this a current issue with protocol lib

Activity

  1. changed the title [-]1.21.x Entity Teleport package has errors[/-] [+]1.21.x Entity Teleport packet has errors[/+] on Mar 27, 2026
  2. kenshineto commented on Mar 27, 2026

    @kenshineto
    Author

    I decompiled nms for both 1.21.11 (the version im having issues with) and 1.20.4 (a version i know works), and as far as I can tell, the PacketPlayOutEntityTeleport.java is the same in both (minor a stream codec thing that isnt even used in the file), so I think my code should work...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions