Modify blockbreaker distance calculations

This commit is contained in:
fullwall 2022-06-25 17:01:02 +08:00
parent 659a5b17ad
commit 8c4b72c5f8

View File

@ -49,10 +49,6 @@ public abstract class AbstractBlockBreaker extends BlockBreaker {
setTarget = false;
}
private double distance() {
return entity.getLocation().distance(Util.getCenterLocation(location.getBlock()));
}
protected abstract float getDamage(int tickDifference);
protected ItemStack getItemStack() {
@ -60,6 +56,13 @@ public abstract class AbstractBlockBreaker extends BlockBreaker {
: entity instanceof LivingEntity ? ((LivingEntity) entity).getEquipment().getItemInHand() : null;
}
private boolean inRange() {
Location center = Util.getCenterLocation(location.getBlock());
Location loc = entity.getLocation();
double xz = Math.sqrt(Math.pow(center.getX() - loc.getX(), 2) + Math.pow(center.getZ() - loc.getZ(), 2));
return xz <= configuration.radius() && Math.abs(center.getY() - loc.getY()) <= 3;
}
@Override
public void reset() {
cancelNavigation();
@ -80,7 +83,7 @@ public abstract class AbstractBlockBreaker extends BlockBreaker {
}
currentTick = (int) (System.currentTimeMillis() / 50);
if (configuration.radius() > 0) {
if (distance() >= configuration.radius()) {
if (!inRange()) {
startDigTick = currentTick;
if (entity instanceof NPCHolder) {
NPC npc = ((NPCHolder) entity).getNPC();