From 47d9330a56bcd009ebf1b389ed5372f136ff6db9 Mon Sep 17 00:00:00 2001 From: fullwall Date: Wed, 9 Aug 2023 21:23:22 +0800 Subject: [PATCH] StraightLineTargetingStrategy should update target --- .../citizensnpcs/npc/ai/MCTargetStrategy.java | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java b/main/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java index 3d9ed26da..b3fff6fc4 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java @@ -220,17 +220,12 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { @Override public Location getCurrentDestination() { - if (active == null) - return null; - return active.getCurrentDestination(); + return active == null ? null : active.getCurrentDestination(); } @Override public Iterable getPath() { - if (active != null) { - return active.getPath(); - } - return fallback.getPath(); + return active != null ? active.getPath() : fallback.getPath(); } @Override @@ -239,14 +234,10 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { if (location == null) throw new IllegalStateException("mapper should not return null"); - if (parameters.straightLineTargetingDistance() > 0) { - double distance = npc.getStoredLocation().distance(location); - if (distance < parameters.straightLineTargetingDistance()) { - if (active == null) { - active = new StraightLineNavigationStrategy(npc, target, parameters); - } - return; - } + if (parameters.straightLineTargetingDistance() > 0 + && npc.getStoredLocation().distance(location) <= parameters.straightLineTargetingDistance()) { + active = new StraightLineNavigationStrategy(npc, target, parameters); + return; } active = null;