Skip to content

Commit

Permalink
feat: better border calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
CuukyOfficial committed Sep 14, 2024
1 parent f104584 commit 4151f7c
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/de/cuuky/varo/game/world/border/VaroWorldBorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,11 @@ private void loadBorder() {

private double getDistanceToBorder(Player player) {
Location playerLoc = player.getLocation();

Location center = getCenter();
double size = getBorderSize() / 2;

ArrayList<Double> distanceArray = new ArrayList<>();
double playerDifferenceX = playerLoc.getX() - center.getX();
double playerDifferenceZ = playerLoc.getZ() - center.getZ();
distanceArray.add(Math.abs(playerDifferenceX + size));
distanceArray.add(Math.abs(playerDifferenceX - size));
distanceArray.add(Math.abs(playerDifferenceZ + size));
distanceArray.add(Math.abs(playerDifferenceZ - size));
double nearest = Double.MAX_VALUE;
for (double distance : distanceArray)
if (distance < nearest)
nearest = distance;

return Math.round(nearest);
double dx = Math.abs(playerLoc.getX() - center.getX()) - size;
double dz = Math.abs(playerLoc.getZ() - center.getZ()) - size;
return Math.abs(Math.max(dx, dz));
}

private void startCalculating() {
Expand Down

0 comments on commit 4151f7c

Please sign in to comment.