From 41ba6b1f645dea40736a7d0a90e9146244737640 Mon Sep 17 00:00:00 2001 From: fullwall Date: Mon, 24 Sep 2012 16:40:13 +0800 Subject: [PATCH] Fix some navigation bugs (thanks jrbudda) --- .gitignore | 3 ++- .../java/net/citizensnpcs/npc/ai/CitizensNavigator.java | 4 ++++ .../java/net/citizensnpcs/npc/entity/EntityHumanNPC.java | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0ba3af2e6..9c512b0a1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /target .classpath .project -Citizens.jar \ No newline at end of file +Citizens.jar +*.lnk \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index 6c82f49b9..741079310 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -140,6 +140,10 @@ public class CitizensNavigator implements Navigator { executing = null; localParams = defaultParams; stationaryTicks = 0; + if (npc.isSpawned()) { + EntityLiving entity = npc.getHandle(); + entity.motX = entity.motY = entity.motZ = 0F; + } } private void stopNavigating(CancelReason reason) { diff --git a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java index 516b432d8..49442d4fe 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java @@ -116,7 +116,10 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { navigation.e(); moveOnCurrentHeading(); } else if (!npc.getNavigator().isNavigating() && (motX != 0 || motZ != 0 || motY != 0)) { - e(0, 0);// is this necessary? it does gravity/controllable but + if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON) { + motX = motY = motZ = 0; + } else + e(0, 0); // is this necessary? it does gravity/controllable but // sometimes players sink into the ground } if (noDamageTicks > 0) @@ -180,5 +183,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { as = yaw; // update head yaw to match entity yaw } + private static final float EPSILON = 0.001F; + private static final float STEP_HEIGHT = 1F; } \ No newline at end of file