Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-4686

Client movement when teleported


    • Icon: Bug Bug
    • Resolution: Fixed
    • Minecraft 1.4.5, Snapshot 12w50b, Snapshot 13w10a, Minecraft 1.5, Snapshot 13w11a, Minecraft 1.5.1, Minecraft 1.5.2, Snapshot 13w17a, Snapshot 13w18b, Snapshot 13w18c, Snapshot 13w19a, Snapshot 13w21b, Snapshot 13w26a, Minecraft 1.6.2, Minecraft 14w33c, Minecraft 14w34b, Minecraft 1.8-pre1, Minecraft 1.8-pre3, Minecraft 1.8, Minecraft 1.8.1-pre3, Minecraft 1.8.1-pre4, Minecraft 1.8.1, Minecraft 1.8.8, Minecraft 15w35e, Minecraft 1.8.9, Minecraft 16w02a, Minecraft 16w05a, Minecraft 16w05b, Minecraft 16w06a, Minecraft 16w07a, Minecraft 1.9 Pre-Release 2, Minecraft 1.9 Pre-Release 3, Minecraft 1.9 Pre-Release 4, Minecraft 1.9, Minecraft 1.9.1 Pre-Release 3, Minecraft 1.9.2, Minecraft 1.9.3 Pre-Release 1, Minecraft 1.9.3 Pre-Release 2, Minecraft 1.9.4, Minecraft 1.10 Pre-Release 1, Minecraft 1.10, Minecraft 16w32b, Minecraft 16w33a, Minecraft 16w44a, Minecraft 1.11, Minecraft 1.11.2, Minecraft 17w06a, Minecraft 17w13b, Minecraft 1.12, Minecraft 1.12.1, Minecraft 1.12.2 Pre-Release 1, Minecraft 1.12.2 Pre-Release 2, Minecraft 1.12.2, Minecraft 17w48a, Minecraft 18w01a, Minecraft 18w02a, Minecraft 18w03b, Minecraft 18w06a, Minecraft 18w10d, Minecraft 18w11a, Minecraft 18w14b, Minecraft 18w15a, Minecraft 18w16a, Minecraft 18w19b, Minecraft 18w20a, Minecraft 18w20c, Minecraft 18w21a, Minecraft 18w22c, Minecraft 1.13-pre1, Minecraft 1.13-pre2, Minecraft 1.13-pre3, Minecraft 1.13-pre5, Minecraft 1.13-pre6, Minecraft 1.13-pre8, Minecraft 1.13-pre9, Minecraft 1.13-pre10, Minecraft 1.13, Minecraft 18w30b, Minecraft 18w31a, Minecraft 18w32a, Minecraft 1.13.1-pre1, Minecraft 1.13.1-pre2, Minecraft 1.13.1, Minecraft 1.13.2
    • Confirmed

      The bug

      Currently, when teleporting a player (either relatively or absolutely) the motion of the teleport is visible sometimes, but not always. This behaviour is inconsistent even at 60fps.

      How to reproduce

      1. Make two identical buildings 16 blocks apart from each other on the worlds X axis
      2. Keep executing the following two commands
        /tp ~16 ~ ~
        /tp ~-16 ~ ~

        → Note the occasional flash in between the teleports


      When a teleportation occurs, a flash is sometimes seen. Sometimes blocks even disappear until you move your mouse.
      This flash is caused by extra frames generated during the teleportation. Causing an image to be rendered from the position in between the start position and the destination. The disappearing blocks is a different issue that deserves its own ticket.


      To either not see a flash at all, or see it all the time (at 60fps).

      Possible fix

      It appears that this happens because only one of the two previous position fields is updated when teleporting. Specifically, setPositionAndRotation updates prevPosX/Y/Z, but leaves lastTickX/Y/Z alone. Both of these fields are used to interpolate position (each in different contexts), and only using one causes this bug. (Side note: I'm not entirely sure why there are two fields that have more or less the same purpose - perhaps they can be merged).

      This is my (pokechu22) fix (in NetHandlerPlayClient.handlePlayerPosLook):

      EntityPlayer player = this.gameController.player;
      double x = packetIn.getX();
      double y = packetIn.getY();
      double z = packetIn.getZ();
      float yaw = packetIn.getYaw();
      float pitch = packetIn.getPitch();
      if (packetIn.getFlags().contains(SPacketPlayerPosLook.EnumFlags.X))
          player.lastTickPosX += x;
          player.chasingPosX += x;
          player.prevChasingPosX += x;
          x += player.posX;
          player.lastTickPosX = x;
          player.chasingPosX = x;
          player.prevChasingPosX = x;
          player.motionX = 0.0D;
      if (packetIn.getFlags().contains(SPacketPlayerPosLook.EnumFlags.Y))
          player.lastTickPosY += y;
          player.chasingPosY += y;
          player.prevChasingPosY += y;
          y += player.posY;
          player.lastTickPosY = y;
          player.chasingPosY = y;
          player.prevChasingPosY = y;
          player.motionY = 0.0D;
      if (packetIn.getFlags().contains(SPacketPlayerPosLook.EnumFlags.Z))
          player.lastTickPosZ += z;
          player.chasingPosZ += z;
          player.prevChasingPosZ += z;
          z += player.posZ;
          player.lastTickPosZ = z;
          player.chasingPosZ = z;
          player.prevChasingPosZ = z;
          player.motionZ = 0.0D;

      I update lastTickPosX/Y/Z by the delta if it is a relative teleport, and set it directly if it is an absolute teleport. Changing it by the delta is important - if we just set it to the new position, then there actually is a (subtle) pause as the camera stays in the new position for the entire tick rather than moving between the offset old position and the new position.

      I also update prevChasingPos/chasingPosX/Y/Z, which are used to render capes. This keeps capes from spazing out when teleporting (but isn't too important to the core problem).

      I don't touch prevPosX/Y/Z at all in this code, simply because any changes made would be overwritten by the call to setPositionAndRotation. It may be better to also adjust prevPosX/Y/Z by the delta, but I couldn't detect a significant difference and that would require tweaking setPositionAndRotation.

      (note that MC-120545 needs to also be fixed for seamless teleporting)

        1. 13e3x.gif
          1.53 MB
        2. 2012-12-14_22.09.17.png
          327 kB
        3. 2012-12-14_22.09.27.png
          156 kB
        4. 2012-12-14_22.09.36.png
          113 kB
        5. 2013-04-13_17.42.28.png
          320 kB
        6. New World-.zip
          220 kB
        7. tp on a clock.zip
          275 kB

            rherlitz Rikard Herlitz
            jespertheend Jesper the End
            138 Vote for this issue
            60 Start watching this issue