From a9ff8f150919c6f730c0a9acd5149d8dff7e092c Mon Sep 17 00:00:00 2001 From: fullwall Date: Mon, 3 Sep 2012 22:12:38 +0800 Subject: [PATCH] Changes to navigator --- .../citizensnpcs/npc/ai/CitizensNavigator.java | 10 +++++++--- .../npc/ai/MCNavigationStrategy.java | 18 +++++++----------- .../citizensnpcs/npc/ai/MCTargetStrategy.java | 2 ++ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index ad149c85d..de6dfe5d1 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -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; } diff --git a/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java b/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java index 6c47c536c..bd57ad609 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java +++ b/src/main/java/net/citizensnpcs/npc/ai/MCNavigationStrategy.java @@ -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 diff --git a/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java b/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java index 601ae5691..2050bfa13 100644 --- a/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java +++ b/src/main/java/net/citizensnpcs/npc/ai/MCTargetStrategy.java @@ -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;