From 49630258253777c7e8041f8a053bfae752a56d2a Mon Sep 17 00:00:00 2001 From: Dawson <30784509+funkemunky@users.noreply.github.com> Date: Sat, 10 Sep 2022 12:31:11 -0400 Subject: [PATCH] Improving hitbox detection sensitivity --- .../brighten/ac/check/impl/combat/Hitbox.java | 29 ++++++++++--------- .../ac/handler/EntityLocationHandler.java | 6 ++++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/main/java/dev/brighten/ac/check/impl/combat/Hitbox.java b/src/main/java/dev/brighten/ac/check/impl/combat/Hitbox.java index af5e7e9..8d1afb4 100644 --- a/src/main/java/dev/brighten/ac/check/impl/combat/Hitbox.java +++ b/src/main/java/dev/brighten/ac/check/impl/combat/Hitbox.java @@ -25,7 +25,7 @@ public class Hitbox extends Check { private float buffer; private int hbuffer; - public Timer lastAimOnTarget = new TickTimer(); + public Timer lastAimOnTarget = new TickTimer(), lastPosition = new TickTimer(); private final Queue> attacks = new LinkedBlockingQueue<>(); private static final EnumSet allowedEntityTypes = EnumSet.of(EntityType.ZOMBIE, EntityType.SHEEP, @@ -75,34 +75,35 @@ public class Hitbox extends Check { boolean collided = false; //Using this to compare smaller numbers than Double.MAX_VALUE. Slightly faster List boxes = new ArrayList<>(); + double expand = 0.005; + if(player.getPlayerVersion().isBelow(ProtocolVersion.V1_9)) { + expand+= 0.1; + } + + //Accounting for potential movement updates not sent to the server + if(lastPosition.isPassed(1)) { + expand+= 0.03; + } + if(eloc.two != null) { for (KLocation oldLocation : eloc.one.interpolatedLocations) { SimpleCollisionBox box = (SimpleCollisionBox) EntityData.getEntityBox(oldLocation.toVector(), target.one); - if(player.getPlayerVersion().isBelow(ProtocolVersion.V1_9)) { - box = box.expand(0.1325); - } else box = box.expand(0.0325); - boxes.add(box); + boxes.add(box.expand(expand)); } for (KLocation oldLocation : eloc.two.interpolatedLocations) { SimpleCollisionBox box = (SimpleCollisionBox) EntityData.getEntityBox(oldLocation.toVector(), target.one); - if(player.getPlayerVersion().isBelow(ProtocolVersion.V1_9)) { - box = box.expand(0.1325); - } else box = box.expand(0.0325); - boxes.add(box); + boxes.add(box.expand(expand)); } } else { for (KLocation oldLocation : eloc.one.interpolatedLocations) { SimpleCollisionBox box = (SimpleCollisionBox) EntityData.getEntityBox(oldLocation.toVector(), target.one); - if(player.getPlayerVersion().isBelow(ProtocolVersion.V1_9)) { - box = box.expand(0.1325); - } else box = box.expand(0.0325); - boxes.add(box); + boxes.add(box.expand(expand)); } } @@ -178,6 +179,8 @@ public class Hitbox extends Check { debug("Missed!"); } } + if(packet.isMoved()) + lastPosition.reset(); }; } diff --git a/src/main/java/dev/brighten/ac/handler/EntityLocationHandler.java b/src/main/java/dev/brighten/ac/handler/EntityLocationHandler.java index 816f804..70b3f82 100644 --- a/src/main/java/dev/brighten/ac/handler/EntityLocationHandler.java +++ b/src/main/java/dev/brighten/ac/handler/EntityLocationHandler.java @@ -58,9 +58,15 @@ public class EntityLocationHandler { entityLocationMap.values().forEach(eloc -> { if(eloc.one != null) { + if(eloc.one.interpolatedLocations.size() > 1 && eloc.one.increment == 0) { + eloc.one.interpolatedLocations.removeFirst(); + } eloc.one.interpolateLocation(); } if(eloc.two != null) { + if(eloc.two.interpolatedLocations.size() > 1 && eloc.two.increment == 0) { + eloc.two.interpolatedLocations.removeFirst(); + } eloc.two.interpolateLocation(); } });