Last active
September 17, 2022 00:52
-
-
Save Yuhtin/ea87c9f5a5c83089613a50b1d7ef9ac2 to your computer and use it in GitHub Desktop.
Check if location is inside a Player hitbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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
Font: https://www.spigotmc.org/threads/class-hitbox-class-check-if-a-player-is-inside-a-location.136740/
Owner: https://github.com/2008Choco