Use new parameter and debug

This commit is contained in:
fullwall 2014-01-12 17:45:16 +08:00
parent 66a07f8f05
commit a95b339515
2 changed files with 14 additions and 8 deletions

View File

@ -30,12 +30,16 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
this.destination = dest; this.destination = dest;
this.npc = npc; this.npc = npc;
Location location = Util.getEyeLocation(npc.getEntity()); Location location = Util.getEyeLocation(npc.getEntity());
plan = ASTAR.runFully(new VectorGoal(dest, (float) params.distanceMargin()), new VectorNode(location, VectorGoal goal = new VectorGoal(dest, (float) params.pathDistanceMargin());
new ChunkBlockSource(location, params.range()), params.examiners()), 50000); plan = ASTAR.runFully(goal, new VectorNode(goal, location, new ChunkBlockSource(location, params.range()),
params.examiners()), 50000);
if (plan == null || plan.isComplete()) { if (plan == null || plan.isComplete()) {
setCancelReason(CancelReason.STUCK); setCancelReason(CancelReason.STUCK);
} else { } else {
vector = plan.getCurrentVector(); vector = plan.getCurrentVector();
if (Setting.DEBUG_PATHFINDING.asBoolean()) {
plan.debug();
}
} }
} }
@ -57,6 +61,9 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
if (npc.getEntity().getLocation(NPC_LOCATION).toVector().distanceSquared(vector) <= params.distanceMargin()) { if (npc.getEntity().getLocation(NPC_LOCATION).toVector().distanceSquared(vector) <= params.distanceMargin()) {
plan.update(npc); plan.update(npc);
if (plan.isComplete()) { if (plan.isComplete()) {
if (Setting.DEBUG_PATHFINDING.asBoolean()) {
plan.debugEnd();
}
return true; return true;
} }
vector = plan.getCurrentVector(); vector = plan.getCurrentVector();
@ -68,11 +75,9 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
double xzDistance = dX * dX + dZ * dZ; double xzDistance = dX * dX + dZ * dZ;
double distance = xzDistance + dY * dY; double distance = xzDistance + dY * dY;
if (Setting.DEBUG_PATHFINDING.asBoolean()) { if (Setting.DEBUG_PATHFINDING.asBoolean()) {
for (int i = 0; i < 3; i++) {
npc.getEntity().getWorld() npc.getEntity().getWorld()
.playEffect(vector.toLocation(npc.getEntity().getWorld()), Effect.ENDER_SIGNAL, 0); .playEffect(vector.toLocation(npc.getEntity().getWorld()), Effect.ENDER_SIGNAL, 0);
} }
}
if (distance > 0 && dY > 0 && dY < 1 && xzDistance <= 2.75) { if (distance > 0 && dY > 0 && dY < 1 && xzDistance <= 2.75) {
NMS.setShouldJump(npc.getEntity()); NMS.setShouldJump(npc.getEntity());
} }

View File

@ -29,8 +29,9 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
this.parameters = params; this.parameters = params;
this.npc = npc; this.npc = npc;
Location location = Util.getEyeLocation(npc.getEntity()); Location location = Util.getEyeLocation(npc.getEntity());
plan = ASTAR.runFully(new VectorGoal(dest, (float) params.distanceMargin()), new VectorNode(location, VectorGoal goal = new VectorGoal(dest, (float) params.pathDistanceMargin());
new ChunkBlockSource(location, params.range()), params.examiners()), 50000); plan = ASTAR.runFully(goal, new VectorNode(goal, location, new ChunkBlockSource(location, params.range()),
params.examiners()), 50000);
if (plan == null || plan.isComplete()) { if (plan == null || plan.isComplete()) {
setCancelReason(CancelReason.STUCK); setCancelReason(CancelReason.STUCK);
} else { } else {