Improve RoboWalk (#228)

This commit is contained in:
DesiCow
2023-03-18 13:54:22 +05:30
committed by GitHub
parent 5ea6ad2ba1
commit e33ecf441e

View File

@@ -15,13 +15,8 @@ public class RoboWalk extends Module {
}
private double smooth(double d) {
return Math.round(d * 100.0d) / 100.0d;
}
private boolean skip(double x, double z) {
long dx = ((long) (x * 1000)) % 10;
long dz = ((long) (z * 1000)) % 10;
return dx != 0 || dz != 0;
double temp = (double) Math.round(d * 100) / 100;
return Math.nextAfter(temp, temp + Math.signum(d));
}
@EventHandler
@@ -32,16 +27,12 @@ public class RoboWalk extends Module {
double x = smooth(packet.getX(0));
double z = smooth(packet.getZ(0));
if (skip(x, z)) return;
((PlayerMoveC2SPacketAccessor) packet).setX(x);
((PlayerMoveC2SPacketAccessor) packet).setZ(z);
} else if (event.packet instanceof VehicleMoveC2SPacket packet) {
double x = smooth(packet.getX());
double z = smooth(packet.getZ());
if (skip(x, z)) return;
((VehicleMoveC2SPacketAccessor) packet).setX(x);
((VehicleMoveC2SPacketAccessor) packet).setZ(z);
}