From d0366bccdef12f5930b071a72935988e98d6ca63 Mon Sep 17 00:00:00 2001 From: fullwall Date: Wed, 22 Jun 2022 12:13:10 +0800 Subject: [PATCH] Measure block breaker distance from center block --- .../java/net/citizensnpcs/util/AbstractBlockBreaker.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/util/AbstractBlockBreaker.java b/main/src/main/java/net/citizensnpcs/util/AbstractBlockBreaker.java index 469b131e3..14b97af62 100644 --- a/main/src/main/java/net/citizensnpcs/util/AbstractBlockBreaker.java +++ b/main/src/main/java/net/citizensnpcs/util/AbstractBlockBreaker.java @@ -36,8 +36,7 @@ public abstract class AbstractBlockBreaker extends BlockBreaker { } private double distance() { - Location loc = entity.getLocation(); - return Math.sqrt(Math.pow(loc.getX() - x, 2) + Math.pow(loc.getZ() - z, 2)); + return entity.getLocation().distance(Util.getCenterLocation(location.getBlock())); } protected abstract float getDamage(int tickDifference); @@ -78,7 +77,7 @@ public abstract class AbstractBlockBreaker extends BlockBreaker { NPC npc = ((NPCHolder) entity).getNPC(); if (npc != null && !npc.getNavigator().isNavigating()) { npc.getNavigator().setTarget(location.clone().add(0, 1, 0)); - npc.getNavigator().getLocalParameters().distanceMargin(configuration.radius() - 1); + npc.getNavigator().getLocalParameters().distanceMargin(Math.max(configuration.radius() - 1, 0.5)); setTarget = true; } } @@ -112,5 +111,4 @@ public abstract class AbstractBlockBreaker extends BlockBreaker { public boolean shouldExecute() { return !entity.getWorld().getBlockAt(x, y, z).isEmpty(); } - } \ No newline at end of file