Fix Enderman, Horse and Wither not moving properly, fix Player NPCs not jumping properly

This commit is contained in:
fullwall 2013-07-19 15:22:36 +08:00
parent fdadd1df8b
commit d030909524
6 changed files with 113 additions and 8 deletions

View File

@ -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) {

View File

@ -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--;
}
}
}
}

View File

@ -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) {

View File

@ -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 {

View File

@ -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 {

View File

@ -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();
}
}
}