Fix NPC targeting

This commit is contained in:
fullwall 2016-03-16 21:19:31 +08:00
parent 7d96b5ad6d
commit 33f9c251ca
2 changed files with 15 additions and 1 deletions

View File

@ -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, " <a>Traits<e>");
for (Trait trait : npc.getTraits()) {
if (CitizensAPI.getTraitFactory().isInternalTrait(trait))

View File

@ -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() {