From 23ab7664a2e0e0510124a309cf60d2a548bce744 Mon Sep 17 00:00:00 2001 From: fullwall Date: Fri, 2 Mar 2012 19:39:47 +0800 Subject: [PATCH] Attempted fixes --- .../net/citizensnpcs/npc/ai/MoveStrategy.java | 4 ++++ .../trait/waypoint/GenericWaypointCallback.java | 15 ++++++++++----- .../trait/waypoint/LinearWaypointProvider.java | 14 ++++++++------ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/citizensnpcs/npc/ai/MoveStrategy.java b/src/main/java/net/citizensnpcs/npc/ai/MoveStrategy.java index 4b4d7ff8e..97b8b7f0b 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/MoveStrategy.java +++ b/src/main/java/net/citizensnpcs/npc/ai/MoveStrategy.java @@ -4,6 +4,7 @@ import java.lang.reflect.Field; import java.util.Random; import net.citizensnpcs.npc.CitizensNPC; +import net.citizensnpcs.util.Messaging; import net.minecraft.server.EntityLiving; import net.minecraft.server.MathHelper; import net.minecraft.server.PathEntity; @@ -18,6 +19,7 @@ public class MoveStrategy implements PathStrategy { private final EntityLiving handle; private final PathEntity path; private final Random random = new Random(); + public MoveStrategy(CitizensNPC handle, Location destination) { this.handle = handle.getHandle(); this.path = this.handle.world.a(this.handle, destination.getBlockX(), destination.getBlockY(), @@ -79,6 +81,7 @@ public class MoveStrategy implements PathStrategy { e.printStackTrace(); } } + Messaging.log(cachedSpeed); handle.e(cachedSpeed); // handle.walk(); @@ -95,6 +98,7 @@ public class MoveStrategy implements PathStrategy { static { try { SPEED_FIELD = EntityLiving.class.getDeclaredField("bb"); + SPEED_FIELD.setAccessible(true); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { diff --git a/src/main/java/net/citizensnpcs/trait/waypoint/GenericWaypointCallback.java b/src/main/java/net/citizensnpcs/trait/waypoint/GenericWaypointCallback.java index 839d842f4..6025ce1c8 100644 --- a/src/main/java/net/citizensnpcs/trait/waypoint/GenericWaypointCallback.java +++ b/src/main/java/net/citizensnpcs/trait/waypoint/GenericWaypointCallback.java @@ -9,12 +9,17 @@ import org.bukkit.Location; public class GenericWaypointCallback extends NavigationCallback { private Location dest; + private AI ai; private boolean executing; private Iterator itr; private final Iterable provider; public GenericWaypointCallback(Iterable provider) { this.provider = provider; + this.itr = provider.iterator(); + if (itr.hasNext()) { + dest = itr.next().getLocation(); + } } private void ensureItr() { @@ -24,6 +29,7 @@ public class GenericWaypointCallback extends NavigationCallback { @Override public void onAttach(AI ai) { + this.ai = ai; executing = !ai.hasDestination(); if (!executing) return; @@ -57,11 +63,7 @@ public class GenericWaypointCallback extends NavigationCallback { @Override public boolean onCompletion(AI ai) { if (executing) { // if we're executing, we need to get the next waypoint - if (!itr.hasNext()) { - dest = null; - } else { - dest = itr.next().getLocation(); - } + dest = itr.hasNext() ? itr.next().getLocation() : null; } else { executing = true; // we're free to return to our waypoints! @@ -76,5 +78,8 @@ public class GenericWaypointCallback extends NavigationCallback { public void onProviderChanged() { itr = provider.iterator(); dest = itr.hasNext() ? itr.next().getLocation() : null; + if (dest != null) { + ai.setDestination(dest); + } } } diff --git a/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java b/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java index e2f495773..fab9905ae 100644 --- a/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java +++ b/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java @@ -10,6 +10,7 @@ import net.citizensnpcs.editor.Editor; import net.citizensnpcs.util.Messaging; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; @@ -19,7 +20,6 @@ import com.google.common.collect.Lists; public class LinearWaypointProvider implements WaypointProvider, Iterable { private final GenericWaypointCallback callback = new GenericWaypointCallback(this); - private final List waypoints = Lists.newArrayList(); @Override @@ -28,12 +28,12 @@ public class LinearWaypointProvider implements WaypointProvider, IterableLeft click to add a waypoint, right click to remove."); } @Override public void end() { - player.sendMessage(ChatColor.GREEN + "Exited linear waypoint editor."); + player.sendMessage(ChatColor.AQUA + "Exited the linear waypoint editor."); callback.onProviderChanged(); } @@ -42,10 +42,11 @@ public class LinearWaypointProvider implements WaypointProvider, IterableAdded a waypoint."); + Location at = event.getClickedBlock().getLocation(); + waypoints.add(new Waypoint(at)); + Messaging.send(player, String.format("Added a waypoint at (%d, %d, %d).", + at.getBlockX(), at.getBlockY(), at.getBlockZ())); } else if (waypoints.size() > 0) { waypoints.remove(waypoints.size() - 1); Messaging.send(player, @@ -70,6 +71,7 @@ public class LinearWaypointProvider implements WaypointProvider, Iterable