}
@Override
public List<Message> getUpdateMessages(Entity entity, Transform liveTransform, RepositionManager rm, boolean force) {
// Movement
final Transform prevTransform = rm.convert(entity.getPhysics().getTransform());
final Transform newTransform = rm.convert(liveTransform);
final boolean looked = entity.getPhysics().isRotationDirty();
final int lastX = protocolifyPosition(prevTransform.getPosition().getX());
final int lastY = protocolifyPosition(prevTransform.getPosition().getY());
final int lastZ = protocolifyPosition(prevTransform.getPosition().getZ());
final Vector3f lastAxesAngles = prevTransform.getRotation().getAxesAngleDeg();
final int lastYaw = protocolifyYaw(lastAxesAngles.getY());
final int lastPitch = protocolifyPitch(lastAxesAngles.getX());
final int newX = protocolifyPosition(newTransform.getPosition().getX());
final int newY = protocolifyPosition(newTransform.getPosition().getY());
final int newZ = protocolifyPosition(newTransform.getPosition().getZ());
final Vector3f newAxesAngles = newTransform.getRotation().getAxesAngleDeg();
final int newYaw = protocolifyYaw(newAxesAngles.getY());
final int newPitch = protocolifyPitch(newAxesAngles.getX());
final int deltaX = newX - lastX;
final int deltaY = newY - lastY;
final int deltaZ = newZ - lastZ;
final int deltaYaw = newYaw - lastYaw;
final int deltaPitch = newPitch - lastPitch;
final List<Message> messages = new ArrayList<Message>();
/*
* Two scenarios:
* - The entity moves more than 4 blocks and maybe changes rotation.
* - The entity moves less than 4 blocks and maybe changes rotation.
*/
if (force || deltaX > 128 || deltaX < -128 || deltaY > 128 || deltaY < -128 || deltaZ > 128 || deltaZ < -128) {
messages.add(new EntityTeleportMessage(entity.getId(), newX, newY, newZ, newYaw, newPitch));
if (force || looked) {
messages.add(new EntityYawMessage(entity.getId(), newYaw, newPitch));
}
} else if (deltaX != 0 || deltaY != 0 || deltaZ != 0 || deltaYaw != 0 || deltaPitch != 0) {
if (looked) {
messages.add(new EntityRelativePositionYawMessage(entity.getId(), deltaX, deltaY, deltaZ, newYaw, newPitch));
} else if (!prevTransform.getPosition().equals(newTransform.getPosition())) {
messages.add(new EntityRelativePositionMessage(entity.getId(), deltaX, deltaY, deltaZ));
}
}
// Head movement