Fix stationary ticks

This commit is contained in:
fullwall 2012-09-03 16:01:45 +08:00
parent 7377093c6a
commit fcf8bf1f88

View File

@ -133,12 +133,14 @@ public class CitizensNavigator implements Navigator {
executing.stop(); executing.stop();
executing = null; executing = null;
localParams = defaultParams; localParams = defaultParams;
stationaryTicks = 0;
} }
private void switchStrategyTo(PathStrategy newStrategy) { private void switchStrategyTo(PathStrategy newStrategy) {
if (executing != null) if (executing != null)
Bukkit.getPluginManager().callEvent(new NavigationReplaceEvent(this)); Bukkit.getPluginManager().callEvent(new NavigationReplaceEvent(this));
executing = newStrategy; executing = newStrategy;
stationaryTicks = 0;
Bukkit.getPluginManager().callEvent(new NavigationBeginEvent(this)); Bukkit.getPluginManager().callEvent(new NavigationBeginEvent(this));
} }
@ -161,16 +163,19 @@ public class CitizensNavigator implements Navigator {
return false; return false;
EntityLiving handle = npc.getHandle(); EntityLiving handle = npc.getHandle();
if ((int) handle.lastX == (int) handle.locX && (int) handle.lastY == (int) handle.locY if ((int) handle.lastX == (int) handle.locX && (int) handle.lastY == (int) handle.locY
&& (int) handle.lastZ == (int) handle.locZ && (int) handle.lastZ == (int) handle.locZ) {
&& ++stationaryTicks >= localParams.stationaryTicks()) { if (++stationaryTicks >= localParams.stationaryTicks()) {
StuckAction action = localParams.stuckAction(); StuckAction action = localParams.stuckAction();
if (action != null) if (action != null)
action.run(npc, this); action.run(npc, this);
Bukkit.getPluginManager().callEvent(new NavigationCancelEvent(this, CancelReason.STUCK)); Bukkit.getPluginManager().callEvent(new NavigationCancelEvent(this, CancelReason.STUCK));
stopNavigating(); stopNavigating();
}
return true; return true;
} }
} else
stationaryTicks = 0;
return false;
}
private static int UNINITIALISED_SPEED = Integer.MIN_VALUE; private static int UNINITIALISED_SPEED = Integer.MIN_VALUE;
} }