Skip to content

Commit

Permalink
Improve RoboWalk (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
DesiCow authored Mar 18, 2023
1 parent 5ea6ad2 commit e33ecf4
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/main/java/anticope/rejects/modules/RoboWalk.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@ public RoboWalk() {
}

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
Expand All @@ -32,16 +27,12 @@ private void onPacketSend(PacketEvent.Send event) {
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);
}
Expand Down

0 comments on commit e33ecf4

Please sign in to comment.