Resource Entity teleportation problems - Fixing entities teleporting incorrectly (slow/inaccurate)

Discussion in 'Spigot Plugin Development' started by MagmaGuy, Apr 17, 2017.

  1. This is a really short resource for very specific issues that I was unable to diagnose for a while and that are so unexpected in nature that it can take quite a few hours to fully understand where things went wrong. In my case, I found it while applying teleportation to and Item.

    These issues seem to originate in the Minecraft client, not the server.

    Both issues derive from the same root issue, although it may not immediately be obvious.

    This resource will (probably) only help you if you are trying to teleport entities every ~4 ticks or less

    Entity isn't teleporting every time / Entity only sometimes teleports

    If you, like me, wanted to pull off some effect by having an entity - be it an item, mob, armor stand, anything really - teleport around really quickly (every 4 ticks or less), you may have noticed that that entity only seems to teleport ~20ticks. If you add some debug code to it, you will be able to tell that the code is running, and if you check the coordinates you will also notice that it is teleporting every time. While the server does teleport the entity every time, the client will either not be able to keep up with the server, and only visually represent the new location of the entity every ~20 ticks.

    Teleported entity, on top of not teleporting as often as you'd like, is not teleporting to the coordinates you are setting

    If you pay close attention to your quickly teleporting entity, you might notice that its coordinates are not correct - this is immediately obvious if you are trying to create a visual effect around an entity. In my case, I found that the effect was visually 0.5 blocks off in the X, Y and Z coordinates. I say visually because I carefully measured them on my client, and then compared them with the console output of getLocation() and, to my surprise, the coordinates that the server was indicating was off by 0.5 blocks compared to the coordinates in my client.


    The fix to this problem is somewhat simple, though problematic: if you want Minecraft to actually render things properly, you'll have to set the refresh rate higher - personally, after a bit of tinkering, I found that changing to 5 ticks seemed to work consistently without skipping teleportations and without making the item slightly shift its coordinates. This also means that whatever visual or practical effect you were trying to do every tick, you'll either have to make it work every 5ish ticks or find an alternative (I am currently experimenting with a mix of teleportations and using setVelocity() ).


    Diagnosing this made me feel like I was losing my mind.
    • Informative Informative x 1