diff --git a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index db6e792fd..361d1880e 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -171,8 +171,9 @@ public class CitizensNavigator implements Navigator, Runnable { } private void stopNavigating() { - if (executing != null) + if (executing != null) { executing.stop(); + } executing = null; localParams = defaultParams; stationaryTicks = 0; @@ -209,8 +210,9 @@ public class CitizensNavigator implements Navigator, Runnable { NavigationCancelEvent event = new NavigationCancelEvent(this, reason); PathStrategy old = executing; Bukkit.getPluginManager().callEvent(event); - if (old == executing) + if (old == executing) { stopNavigating(); + } } private void switchStrategyTo(PathStrategy newStrategy) { diff --git a/src/main/java/net/citizensnpcs/npc/entity/EndermanController.java b/src/main/java/net/citizensnpcs/npc/entity/EndermanController.java index 419bdd2e5..93aedce45 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EndermanController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EndermanController.java @@ -42,6 +42,7 @@ public class EndermanController extends MobEntityController { } public static class EntityEndermanNPC extends EntityEnderman implements NPCHolder { + private int jumpTicks; private final CitizensNPC npc; public EntityEndermanNPC(World world) { @@ -91,7 +92,7 @@ public class EndermanController extends MobEntityController { if (npc == null) super.c(); else { - NMS.updateAI(this); + updateAIWithMovement(); npc.update(); } } @@ -138,5 +139,38 @@ public class EndermanController extends MobEntityController { public NPC getNPC() { return npc; } + + @Override + protected boolean j(double d1, double d2, double d3) { + if (npc == null) { + return super.j(d1, d2, d3); + } + return false; + } + + private void updateAIWithMovement() { + NMS.updateAI(this); + // taken from EntityLiving update method + if (bd) { + /* boolean inLiquid = G() || I(); + if (inLiquid) { + motY += 0.04; + } else //(handled elsewhere)*/ + if (onGround && jumpTicks == 0) { + bd(); + jumpTicks = 10; + } + } else { + jumpTicks = 0; + } + be *= 0.98F; + bf *= 0.98F; + bg *= 0.9F; + e(be, bf); // movement method + NMS.setHeadYaw(this, yaw); + if (jumpTicks > 0) { + jumpTicks--; + } + } } } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java index a1969541c..398cb4d89 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java +++ b/src/main/java/net/citizensnpcs/npc/entity/EntityHumanNPC.java @@ -204,7 +204,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { motY += 0.04; } else //(handled elsewhere)*/ if (onGround && jumpTicks == 0) { - ba(); + bd(); jumpTicks = 10; } } else { @@ -216,6 +216,9 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder { e(be, bf); // movement method NMS.setHeadYaw(this, yaw); + if (jumpTicks > 0) { + jumpTicks--; + } } public void setMoveDestination(double x, double y, double z, float speed) { diff --git a/src/main/java/net/citizensnpcs/npc/entity/HorseController.java b/src/main/java/net/citizensnpcs/npc/entity/HorseController.java index 314348b5c..519a01144 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/HorseController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/HorseController.java @@ -28,6 +28,8 @@ public class HorseController extends MobEntityController { } public static class EntityHorseNPC extends EntityHorse implements NPCHolder { + private int jumpTicks; + private final CitizensNPC npc; public EntityHorseNPC(World world) { @@ -60,8 +62,10 @@ public class HorseController extends MobEntityController { public void c() { if (npc == null) { super.c(); - } else + } else { + updateAIWithMovement(); npc.update(); + } } @Override @@ -69,8 +73,9 @@ public class HorseController extends MobEntityController { // this method is called by both the entities involved - cancelling // it will not stop the NPC from moving. super.collide(entity); - if (npc != null) + if (npc != null) { Util.callCollisionEvent(npc, entity.getBukkitEntity()); + } } @Override @@ -106,6 +111,32 @@ public class HorseController extends MobEntityController { public NPC getNPC() { return npc; } + + private void updateAIWithMovement() { + NMS.updateAI(this); + // taken from EntityLiving update method + if (bd) { + /* boolean inLiquid = G() || I(); + if (inLiquid) { + motY += 0.04; + } else //(handled elsewhere)*/ + if (onGround && jumpTicks == 0) { + bd(); + jumpTicks = 10; + } + } else { + jumpTicks = 0; + } + be *= 0.98F; + bf *= 0.98F; + bg *= 0.9F; + + e(be, bf); // movement method + NMS.setHeadYaw(this, yaw); + if (jumpTicks > 0) { + jumpTicks--; + } + } } public static class HorseNPC extends CraftHorse implements NPCHolder { diff --git a/src/main/java/net/citizensnpcs/npc/entity/WitherController.java b/src/main/java/net/citizensnpcs/npc/entity/WitherController.java index 789eb43d3..c4db41cb9 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/WitherController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/WitherController.java @@ -28,6 +28,7 @@ public class WitherController extends MobEntityController { } public static class EntityWitherNPC extends EntityWither implements NPCHolder { + private int jumpTicks; private final CitizensNPC npc; public EntityWitherNPC(World world) { @@ -67,6 +68,8 @@ public class WitherController extends MobEntityController { public void c() { if (npc == null) { super.c(); + } else { + updateAIWithMovement(); } } @@ -112,6 +115,32 @@ public class WitherController extends MobEntityController { public NPC getNPC() { return npc; } + + private void updateAIWithMovement() { + NMS.updateAI(this); + // taken from EntityLiving update method + if (bd) { + /* boolean inLiquid = G() || I(); + if (inLiquid) { + motY += 0.04; + } else //(handled elsewhere)*/ + if (onGround && jumpTicks == 0) { + bd(); + jumpTicks = 10; + } + } else { + jumpTicks = 0; + } + be *= 0.98F; + bf *= 0.98F; + bg *= 0.9F; + + e(be, bf); // movement method + NMS.setHeadYaw(this, yaw); + if (jumpTicks > 0) { + jumpTicks--; + } + } } public static class WitherNPC extends CraftWither implements NPCHolder { diff --git a/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java b/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java index 6156fa73c..ffb41e54f 100644 --- a/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java +++ b/src/main/java/net/citizensnpcs/trait/waypoint/LinearWaypointProvider.java @@ -326,8 +326,9 @@ public class LinearWaypointProvider implements WaypointProvider { } private void onWaypointsModified() { - if (currentGoal != null) + if (currentGoal != null) { currentGoal.onProviderChanged(); + } } private void removeWaypointMarker(Waypoint waypoint) { @@ -387,7 +388,12 @@ public class LinearWaypointProvider implements WaypointProvider { public void onProviderChanged() { itr = waypoints.iterator(); if (currentDestination != null) { - selector.finish(); + if (selector != null) { + selector.finish(); + } + if (npc != null && npc.getNavigator().isNavigating()) { + npc.getNavigator().cancelNavigation(); + } } }