Improving hitbox detection sensitivity

This commit is contained in:
Dawson
2022-09-10 12:31:11 -04:00
parent 9d1f9122f7
commit 4963025825
2 changed files with 22 additions and 13 deletions
@@ -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<Tuple<Entity, KLocation>> attacks = new LinkedBlockingQueue<>();
private static final EnumSet<EntityType> 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<SimpleCollisionBox> 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();
};
}
@@ -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();
}
});