mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-03-01 02:31:21 +01:00
Add debug for navigation, make sure that destination is in range before calling waypoint triggers
This commit is contained in:
parent
9797d4cdeb
commit
96c8f0d86a
@ -18,6 +18,7 @@ import net.citizensnpcs.api.ai.event.NavigatorCallback;
|
||||
import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.util.NMS;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -190,6 +191,8 @@ public class CitizensNavigator implements Navigator, Runnable {
|
||||
itr.next().onCompletion(reason);
|
||||
itr.remove();
|
||||
}
|
||||
if (Messaging.isDebugging())
|
||||
Messaging.debug(npc.getId(), "cancelling with reason", reason);
|
||||
if (reason == null) {
|
||||
stopNavigating();
|
||||
return;
|
||||
@ -211,6 +214,8 @@ public class CitizensNavigator implements Navigator, Runnable {
|
||||
}
|
||||
|
||||
private void switchStrategyTo(PathStrategy newStrategy) {
|
||||
if (Messaging.isDebugging())
|
||||
Messaging.debug(npc.getId(), "changing to new PathStrategy", newStrategy);
|
||||
if (executing != null)
|
||||
Bukkit.getPluginManager().callEvent(new NavigationReplaceEvent(this));
|
||||
executing = newStrategy;
|
||||
|
@ -46,6 +46,11 @@ public class MCNavigationStrategy extends AbstractPathStrategy {
|
||||
navigation.g();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MCNavigationStrategy [target=" + target + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update() {
|
||||
if (getCancelReason() != null)
|
||||
|
@ -94,6 +94,11 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
|
||||
navigation.g();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MCTargetStrategy [target=" + target + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update() {
|
||||
if (target == null || !target.getBukkitEntity().isValid()) {
|
||||
@ -155,6 +160,7 @@ public class MCTargetStrategy implements PathStrategy, EntityTarget {
|
||||
private static final double ATTACK_DISTANCE = 1.75 * 1.75;
|
||||
private static final Location HANDLE_LOCATION = new Location(null, 0, 0, 0);
|
||||
private static Field NAV_E, NAV_J, NAV_M;
|
||||
|
||||
private static final Location TARGET_LOCATION = new Location(null, 0, 0, 0);
|
||||
|
||||
static {
|
||||
|
@ -419,9 +419,13 @@ public class LinearWaypointProvider implements WaypointProvider {
|
||||
getNavigator().getLocalParameters().addSingleUseCallback(new NavigatorCallback() {
|
||||
@Override
|
||||
public void onCompletion(@Nullable CancelReason cancelReason) {
|
||||
selector.finish();
|
||||
if (currentDestination != null)
|
||||
if (npc.isSpawned()
|
||||
&& currentDestination != null
|
||||
&& Util.locationWithinRange(npc.getBukkitEntity().getLocation(),
|
||||
currentDestination.getLocation(), 4)) {
|
||||
currentDestination.onReach(npc);
|
||||
}
|
||||
selector.finish();
|
||||
}
|
||||
});
|
||||
return true;
|
||||
|
@ -87,6 +87,14 @@ public class Util {
|
||||
return location.getWorld().isChunkLoaded(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
public static boolean locationWithinRange(Location current, Location target, double range) {
|
||||
if (current == null || target == null)
|
||||
return false;
|
||||
if (current.getWorld() != target.getWorld())
|
||||
return false;
|
||||
return current.distanceSquared(target) < Math.pow(range, 2);
|
||||
}
|
||||
|
||||
public static EntityType matchEntityType(String toMatch) {
|
||||
EntityType type = EntityType.fromName(toMatch);
|
||||
if (type != null)
|
||||
|
Loading…
Reference in New Issue
Block a user