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

View File

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

View File

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