Skip to content

Commit

Permalink
Modify blockbreaker distance calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jun 25, 2022
1 parent 659a5b1 commit 8c4b72c
Showing 1 changed file with 8 additions and 5 deletions.
Expand Up @@ -49,17 +49,20 @@ private void cancelNavigation() {
setTarget = false;
}

private double distance() {
return entity.getLocation().distance(Util.getCenterLocation(location.getBlock()));
}

protected abstract float getDamage(int tickDifference);

protected ItemStack getItemStack() {
return configuration.item() != null ? configuration.item()
: 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();
Expand All @@ -80,7 +83,7 @@ public BehaviorStatus run() {
}
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();
Expand Down

0 comments on commit 8c4b72c

Please sign in to comment.