Better pathfinding debug

This commit is contained in:
fullwall 2014-01-12 19:47:05 +08:00
parent a95b339515
commit 0c139a27d4
2 changed files with 18 additions and 5 deletions

View File

@ -15,6 +15,7 @@ import net.citizensnpcs.util.Util;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.util.Vector;
public class AStarNavigationStrategy extends AbstractPathStrategy {
@ -50,6 +51,9 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
@Override
public void stop() {
if (plan != null && Setting.DEBUG_PATHFINDING.asBoolean()) {
plan.debugEnd();
}
plan = null;
}
@ -61,9 +65,6 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
if (npc.getEntity().getLocation(NPC_LOCATION).toVector().distanceSquared(vector) <= params.distanceMargin()) {
plan.update(npc);
if (plan.isComplete()) {
if (Setting.DEBUG_PATHFINDING.asBoolean()) {
plan.debugEnd();
}
return true;
}
vector = plan.getCurrentVector();
@ -76,12 +77,17 @@ public class AStarNavigationStrategy extends AbstractPathStrategy {
double distance = xzDistance + dY * dY;
if (Setting.DEBUG_PATHFINDING.asBoolean()) {
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) {
NMS.setShouldJump(npc.getEntity());
}
NMS.setDestination(npc.getEntity(), vector.getX(), vector.getY(), vector.getZ(), params.speed());
double destX = vector.getX(), destZ = vector.getZ();
if (npc.getEntity().getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()).getType() == Material.LADDER) {
destX += 0.5;
destZ += 0.5;
}
NMS.setDestination(npc.getEntity(), destX, vector.getY(), destZ, params.speed());
params.run();
plan.run(npc);
return false;

View File

@ -1,5 +1,6 @@
package net.citizensnpcs.npc.ai;
import net.citizensnpcs.Settings.Setting;
import net.citizensnpcs.api.ai.NavigatorParameters;
import net.citizensnpcs.api.ai.TargetType;
import net.citizensnpcs.api.ai.event.CancelReason;
@ -36,6 +37,9 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
setCancelReason(CancelReason.STUCK);
} else {
vector = plan.getCurrentVector();
if (Setting.DEBUG_PATHFINDING.asBoolean()) {
plan.debug();
}
}
}
@ -46,6 +50,9 @@ public class FlyingAStarNavigationStrategy extends AbstractPathStrategy {
@Override
public void stop() {
if (plan != null && Setting.DEBUG_PATHFINDING.asBoolean()) {
plan.debugEnd();
}
plan = null;
}