Respect distanceMargin when NPCs are passively moving towards entities

This commit is contained in:
fullwall 2015-01-04 20:51:21 +08:00
parent 95993348bd
commit c1321c2162

View File

@ -34,7 +34,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
this.target = ((CraftEntity) target).getHandle();
NavigationAbstract nav = NMS.getNavigation(this.handle);
this.targetNavigator = nav != null && !params.useNewPathfinder() ? new NavigationFieldWrapper(nav)
: new AStarTargeter();
: new AStarTargeter();
this.aggro = aggro;
}
@ -114,7 +114,9 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
if (cancelReason != null) {
return true;
}
if (target.world.getWorld().getFullTime() % 10 == 0) {
if (!aggro && distanceSquared() < parameters.distanceMargin()) {
stop();
} else if (target.world.getWorld().getFullTime() % 10 == 0) {
setPath();
}
NMS.look(handle, target);
@ -159,7 +161,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
private void setStrategy() {
Location location = target.getBukkitEntity().getLocation(TARGET_LOCATION);
strategy = npc.isFlyable() ? new FlyingAStarNavigationStrategy(npc, location, parameters)
: new AStarNavigationStrategy(npc, location, parameters);
: new AStarNavigationStrategy(npc, location, parameters);
}
@Override