Lagback
Lagback refers to getting teleported back to a previous position. It can be abused to clip inside walls, or jump higher in a similar fashion as Blips. This practice may be a bannable offense on multiplayer servers. In this article, we solely focus on singleplayer 1.8.
Known causes for lagback
- Colliding with a boat
- Falling and sneaking at the last moment
- Moving inside a cobweb too quickly
- Stepping up with an obscene amount of speed (Speed 100, for example)
Explanation
The lagback itself is caused by this portion of code (in class NetHandlerPlayServer):
public void processPlayer(PacketPlayer packetIn)
{
//heavily simplified, ignores exceptional cases where the player is considered inactive (sleeping, teleporting, watching end credits, noclip, flying, mounted)
double posX = this.playerEntity.posX;
double posY = this.playerEntity.posY;
double posZ = this.playerEntity.posZ;
double norm_squared = 0.0D;
double distX = packetIn.getPositionX() - this.lastPosX;
double distY = packetIn.getPositionY() - this.lastPosY;
double distZ = packetIn.getPositionZ() - this.lastPosZ;
double posY_original = this.playerEntity.posY;
this.lastPosX = this.playerEntity.posX;
this.lastPosY = this.playerEntity.posY;
this.lastPosZ = this.playerEntity.posZ;
double e_posX = packetIn.getPositionX();
double e_posY = packetIn.getPositionY();
double e_posZ = packetIn.getPositionZ();
float yaw = this.playerEntity.rotationYaw;
float pitch = this.playerEntity.rotationPitch;
if (packetIn.getRotating()) {yaw = packetIn.getYaw(); pitch = packetIn.getPitch();}
this.playerEntity.onUpdateEntity();
this.playerEntity.setPositionAndRotation(this.lastPosX, this.lastPosY, this.lastPosZ, yaw, pitch);
//the code may stop here under certain circumstances, to be determined.
double deltaX = e_posX - this.playerEntity.posX;
double deltaY = e_posY - this.playerEntity.posY;
double deltaZ = e_posZ - this.playerEntity.posZ;
boolean noCollisionInside = worldserver.getCollidingBoundingBoxes(this.playerEntity, this.playerEntity.getEntityBoundingBox().contract(0.0625, 0.0625, 0.0625).isEmpty();
if (this.playerEntity.onGround && !packetIn.isOnGround() && deltaY > 0.0D)
this.playerEntity.jump();
this.playerEntity.moveEntity(deltaX, deltaY, deltaZ);
this.playerEntity.onGround = packetIn.isOnGround();
double errorX = e_posX - this.playerEntity.posX;
double errorZ = e_posZ - this.playerEntity.posZ;
double error_squared = deltaX * deltaX + deltaZ * deltaZ;
boolean movedWrongly = (delta_squared > 0.0625D && !this.playerEntity.theItemInWorldManager.isCreative());
this.playerEntity.setPositionAndRotation(e_posX, e_posY, e_posZ, yaw, pitch);
boolean noCollisionInside_updated = worldserver.getCollidingBoundingBoxes(this.playerEntity, this.playerEntity.getEntityBoundingBox().contract(0.0625, 0.0625, 0.0625).isEmpty();
if (noCollisionInside && (movedWrongly || !noCollisionInside_updated) && !this.playerEntity.isPlayerSleeping())
{
this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, yaw, pitch);
return;
}
AxisAlignedBB axisalignedbb = this.playerEntity.getEntityBoundingBox().expand(0.0625, 0.0625, 0.0625.addCoord(0.0, -0.55, 0.0);
if (!this.serverController.isFlightAllowed() && !this.playerEntity.capabilities.allowFlying && !worldserver.checkBlockCollision(axisalignedbb))
{
if (deltaY >= -0.03125D)
{
++this.floatingTickCount;
if (this.floatingTickCount > 80)
{
this.kickPlayerFromServer("Flying is not enabled on this server");
return;
}
}
}
else
{
this.floatingTickCount = 0;
}
this.playerEntity.onGround = packetIn.isOnGround();
this.playerEntity.handleFalling(this.playerEntity.posY - posY_original, packetIn.isOnGround());
}
The reason for the desynchronization is still being determined.