Fix getting stuck in wall bug

Due to java doubles being somewhat more "precise" and bedrock positions being sent in floats instead, this caused bedrock players to get stuck in blocks when jumping or running near them in a certain way, thus causing the server to try and correct their position, potentially flagging anticheats and causing the server to print a "moved wrongly" message in console.

See: https://stackoverflow.com/questions/322749/retain-precision-with-double-in-java
This commit is contained in:
RednedEpic 2020-02-25 18:50:09 -06:00
parent 1af4d71bd1
commit f0e01ab1c9
2 changed files with 5 additions and 6 deletions

View File

@ -26,6 +26,7 @@
package org.geysermc.connector.network.translators.bedrock;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket;
import com.nukkitx.math.GenericMath;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket;
import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket;
@ -63,8 +64,7 @@ public class BedrockMovePlayerTranslator extends PacketTranslator<MovePlayerPack
double javaY = Math.ceil((packet.getPosition().getY() - EntityType.PLAYER.getOffset()) * 2) / 2;
ClientPlayerPositionRotationPacket playerPositionRotationPacket = new ClientPlayerPositionRotationPacket(
packet.isOnGround(), packet.getPosition().getX(), javaY,
packet.getPosition().getZ(), packet.getRotation().getY(), packet.getRotation().getX()
packet.isOnGround(), GenericMath.round(packet.getPosition().getX(), 4), javaY, GenericMath.round(packet.getPosition().getZ(), 4), packet.getRotation().getY(), packet.getRotation().getX()
);
// head yaw, pitch, head yaw

View File

@ -87,10 +87,9 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator<Serve
if (!packet.getRelative().isEmpty()) {
entity.moveRelative(session, packet.getX(), packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, packet.getZ(), packet.getYaw(), packet.getPitch(), true);
} else {
float xDis = Math.abs(entity.getPosition().getX() - (float) packet.getX());
float yDis = entity.getPosition().getY() - (float) packet.getY();
float zDis = Math.abs(entity.getPosition().getZ() - (float) packet.getZ());
double xDis = Math.abs(entity.getPosition().getX() - packet.getX());
double yDis = entity.getPosition().getY() - packet.getY();
double zDis = Math.abs(entity.getPosition().getZ() - packet.getZ());
if (xDis > 1.5 || (yDis < 1.45 || yDis > (session.isJumping() ? 4.3 : (session.isSprinting() ? 2.5 : 1.9))) || zDis > 1.5) {
entity.moveAbsolute(session, Vector3f.from(packet.getX(), packet.getY(), packet.getZ()), packet.getYaw(), packet.getPitch(), true);
}