Fix movement when far away from the center of the world (#419)

* Fix movement when far away from the center of the world

* Add comment on why we parse a float as string

Co-authored-by: Redned <redned235@gmail.com>
This commit is contained in:
AJ Ferguson 2020-04-24 19:56:56 -08:00 committed by GitHub
parent e82adf2cf9
commit 357b681841
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -67,8 +67,10 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
double javaY = packet.getPosition().getY() - EntityType.PLAYER.getOffset();
if (packet.isOnGround()) javaY = Math.ceil(javaY * 2) / 2;
// We need to parse the float as a string since casting a float to a double causes us to
// lose precision and thus, causes players to get stuck when walking near walls
ClientPlayerPositionRotationPacket playerPositionRotationPacket = new ClientPlayerPositionRotationPacket(
packet.isOnGround(), GenericMath.round(packet.getPosition().getX(), 4), javaY, GenericMath.round(packet.getPosition().getZ(), 4), packet.getRotation().getY(), packet.getRotation().getX()
packet.isOnGround(), Double.parseDouble(Float.toString(packet.getPosition().getX())), javaY, Double.parseDouble(Float.toString(packet.getPosition().getZ())), packet.getRotation().getY(), packet.getRotation().getX()
);
// head yaw, pitch, head yaw