Skip to content

Instantly share code, notes, and snippets.

@Yuhtin
Last active September 17, 2022 00:52
Show Gist options
  • Save Yuhtin/ea87c9f5a5c83089613a50b1d7ef9ac2 to your computer and use it in GitHub Desktop.
Save Yuhtin/ea87c9f5a5c83089613a50b1d7ef9ac2 to your computer and use it in GitHub Desktop.
Check if location is inside a Player hitbox
@Getter
@AllArgsConstructor
public class Hitbox {
private final Location aa, ab;
public Hitbox(Player player) {
this.aa = player.getLocation().subtract(0.4, 0, 0.4);
this.ab = player.getLocation().add(0.4, 1.8, 0.4);
}
public boolean intersects(Location l) {
boolean isInsideAA = l.getX() <= aa.getX() && l.getY() <= aa.getY() && l.getZ() <= aa.getZ();
boolean isInsideBB = l.getX() >= ab.getX() && l.getY() >= ab.getY() && l.getZ() >= ab.getZ();
return isInsideAA && isInsideBB;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment