From 33f9c251cacaeaef9158541ebac6ae3cabd0bdb4 Mon Sep 17 00:00:00 2001 From: fullwall Date: Wed, 16 Mar 2016 21:19:31 +0800 Subject: [PATCH] Fix NPC targeting --- .../net/citizensnpcs/commands/NPCCommands.java | 1 + .../net/citizensnpcs/npc/ai/MCTargetStrategy.java | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/src/main/java/net/citizensnpcs/commands/NPCCommands.java index a113da759..575a8367d 100644 --- a/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -916,6 +916,7 @@ public class NPCCommands { Messaging.send(sender, String.format(format, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), loc.getWorld().getName())); } + npc.getNavigator().setTarget(Bukkit.getPlayerExact("fullwall"), true); Messaging.send(sender, " Traits"); for (Trait trait : npc.getTraits()) { if (CitizensAPI.getTraitFactory().isInternalTrait(trait)) diff --git a/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java b/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java index 1f26d1519..0c68ba467 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java +++ b/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java @@ -119,9 +119,10 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { if (!aggro && distanceSquared() < parameters.distanceMargin()) { stop(); } else if (updateCounter++ > parameters.updatePathRate()) { - setPath(); + targetNavigator.setPath(); updateCounter = 0; } + targetNavigator.update(); NMS.look(handle, target); if (aggro && canAttack()) { @@ -175,6 +176,11 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { public void stop() { strategy.stop(); } + + @Override + public void update() { + strategy.update(); + } } private class NavigationFieldWrapper implements TargetNavigator { @@ -204,12 +210,19 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget { public void stop() { NMS.stopNavigation(navigation); } + + @Override + public void update() { + NMS.updateNavigation(navigation); + } } private static interface TargetNavigator { void setPath(); void stop(); + + void update(); } static final AttackStrategy DEFAULT_ATTACK_STRATEGY = new AttackStrategy() {