Fix some bugs

This commit is contained in:
fullwall 2012-02-28 22:17:49 +08:00
parent 816545cf59
commit f89aac853d
4 changed files with 20 additions and 6 deletions

View File

@ -79,6 +79,13 @@ public class CitizensAI implements AI {
}
}
executing = new MoveStrategy(npc, destination);
Iterator<WeakReference<NavigationCallback>> itr = callbacks.iterator();
while (itr.hasNext()) {
NavigationCallback next = itr.next().get();
if (next == null || next.onBegin(this)) {
itr.remove();
}
}
}
@Override
@ -114,6 +121,7 @@ public class CitizensAI implements AI {
if (paused)
return;
if (executing != null && executing.update()) {
Messaging.log("finished");
Iterator<WeakReference<NavigationCallback>> itr = callbacks.iterator();
while (itr.hasNext()) {
NavigationCallback next = itr.next().get();

View File

@ -19,7 +19,7 @@ public class MoveStrategy implements PathStrategy {
private final Random random = new Random();
public MoveStrategy(CitizensNPC handle, Location destination) {
this.handle = (EntityLiving) handle.getHandle();
this.handle = handle.getHandle();
this.path = this.handle.world.a(this.handle, destination.getBlockX(), destination.getBlockY(),
destination.getBlockZ(), 16F);
}

View File

@ -32,6 +32,12 @@ public class LinearWaypointProvider implements WaypointProvider {
@Override
public void end() {
player.sendMessage(ChatColor.GREEN + "Exited linear waypoint editor.");
if (waypoints.size() == 0)
callback.currentIndex = -1;
else if (callback.ai != null && callback.currentIndex == -1) {
callback.currentIndex = 0;
callback.ai.setDestination(waypoints.get(0).getLocation());
}
}
@EventHandler
@ -39,6 +45,7 @@ public class LinearWaypointProvider implements WaypointProvider {
public void onPlayerInteract(PlayerInteractEvent event) {
if (!event.getPlayer().equals(player))
return;
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
waypoints.add(new Waypoint(event.getClickedBlock().getLocation()));
Messaging.send(player, "<e>Added<a> a waypoint.");
@ -47,10 +54,6 @@ public class LinearWaypointProvider implements WaypointProvider {
Messaging.send(player,
String.format("<e>Removed<a> a waypoint (<e>%d<a> remaining)", waypoints.size()));
}
if (waypoints.size() == 0)
callback.currentIndex = -1;
else if (callback.currentIndex == -1)
callback.currentIndex = 0;
}
};
}
@ -79,7 +82,8 @@ public class LinearWaypointProvider implements WaypointProvider {
private class LinearNavigationCallback extends NavigationCallback {
private boolean executing;
private int currentIndex;
private int currentIndex = -1;
private AI ai;
@Override
public boolean onCancel(AI ai, PathCancelReason reason) {
@ -98,6 +102,7 @@ public class LinearWaypointProvider implements WaypointProvider {
@Override
public void onAttach(AI ai) {
this.ai = ai;
executing = false;
currentIndex = -1;
cycle();

View File

@ -19,6 +19,7 @@ public class Waypoints extends Trait {
public Waypoints(NPC npc) {
this.npc = npc;
npc.getAI().registerNavigationCallback(provider.getCallback());
}
@Override