Changes to navigator

This commit is contained in:
fullwall 2012-09-03 22:12:38 +08:00
parent fae265b22b
commit f75b33dfce
3 changed files with 16 additions and 14 deletions

View File

@ -160,12 +160,13 @@ public class CitizensNavigator implements Navigator {
NMS.updatePathfindingRange(npc, localParams.range()); NMS.updatePathfindingRange(npc, localParams.range());
} }
int lastX, lastY, lastZ;
private boolean updateStationaryStatus() { private boolean updateStationaryStatus() {
if (localParams.stationaryTicks() < 0) if (localParams.stationaryTicks() < 0)
return false; localParams.stationaryTicks(100);// return false;
EntityLiving handle = npc.getHandle(); EntityLiving handle = npc.getHandle();
if ((int) handle.lastX == (int) handle.locX && (int) handle.lastY == (int) handle.locY if (lastX == (int) handle.locX && lastY == (int) handle.locY && lastZ == (int) handle.locZ) {
&& (int) handle.lastZ == (int) handle.locZ) {
if (++stationaryTicks >= localParams.stationaryTicks()) { if (++stationaryTicks >= localParams.stationaryTicks()) {
StuckAction action = localParams.stuckAction(); StuckAction action = localParams.stuckAction();
if (action != null) if (action != null)
@ -176,6 +177,9 @@ public class CitizensNavigator implements Navigator {
} }
} else } else
stationaryTicks = 0; stationaryTicks = 0;
lastX = (int) handle.locX;
lastY = (int) handle.locY;
lastZ = (int) handle.locZ;
return false; return false;
} }

View File

@ -3,11 +3,10 @@ package net.citizensnpcs.npc.ai;
import net.citizensnpcs.api.ai.NavigatorParameters; import net.citizensnpcs.api.ai.NavigatorParameters;
import net.citizensnpcs.api.ai.TargetType; import net.citizensnpcs.api.ai.TargetType;
import net.citizensnpcs.npc.CitizensNPC; import net.citizensnpcs.npc.CitizensNPC;
import net.minecraft.server.EntityLiving; import net.minecraft.server.EntityPlayer;
import net.minecraft.server.Navigation; import net.minecraft.server.Navigation;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player;
public class MCNavigationStrategy implements PathStrategy { public class MCNavigationStrategy implements PathStrategy {
private final Navigation navigation; private final Navigation navigation;
@ -15,20 +14,17 @@ public class MCNavigationStrategy implements PathStrategy {
private final Location target; private final Location target;
MCNavigationStrategy(final CitizensNPC npc, Location dest, NavigatorParameters params) { MCNavigationStrategy(final CitizensNPC npc, Location dest, NavigatorParameters params) {
this(npc.getHandle(), dest, params); this.target = dest;
navigation.a(dest.getX(), dest.getY(), dest.getZ(), parameters.speed());
}
private MCNavigationStrategy(EntityLiving entity, Location target, NavigatorParameters params) {
this.target = target;
this.parameters = params; this.parameters = params;
if (entity.getBukkitEntity() instanceof Player) { if (npc.getHandle() instanceof EntityPlayer) {
entity.onGround = true; npc.getHandle().onGround = true;
// not sure of a better way around this - if onGround is false, then // not sure of a better way around this - if onGround is false, then
// navigation won't execute, and calling entity.move doesn't // navigation won't execute, and calling entity.move doesn't
// entirely fix the problem. // entirely fix the problem.
} }
navigation = entity.getNavigation(); navigation = npc.getHandle().getNavigation();
navigation.a(parameters.avoidWater());
navigation.a(dest.getX(), dest.getY(), dest.getZ(), parameters.speed());
} }
@Override @Override

View File

@ -28,6 +28,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
this.navigation = this.handle.getNavigation(); this.navigation = this.handle.getNavigation();
this.aggro = aggro; this.aggro = aggro;
this.parameters = params; this.parameters = params;
this.navigation.a(parameters.avoidWater());
} }
private boolean canAttack() { private boolean canAttack() {
@ -88,6 +89,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
return false; return false;
} }
private static final int ATTACK_DELAY_TICKS = 20; private static final int ATTACK_DELAY_TICKS = 20;
private static final double ATTACK_DISTANCE = 1.75 * 1.75; private static final double ATTACK_DISTANCE = 1.75 * 1.75;