From a8fe35a19dce0d87b78f5e00427d250da41c7bcb Mon Sep 17 00:00:00 2001 From: fullwall Date: Fri, 9 Mar 2018 18:36:43 +0800 Subject: [PATCH] Implement SwimmingExaminer --- .../npc/ai/CitizensNavigator.java | 48 ++----------------- .../npc/ai/EnhancedMovementExaminer.java | 2 +- .../waypoint/GuidedWaypointProvider.java | 7 +-- 3 files changed, 8 insertions(+), 49 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java b/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java index 137a36b66..9e7944adb 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/CitizensNavigator.java @@ -1,17 +1,11 @@ package net.citizensnpcs.npc.ai; import java.util.Iterator; -import java.util.ListIterator; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.BlockState; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; -import org.bukkit.material.Door; import org.bukkit.util.Vector; import com.google.common.collect.Iterables; @@ -31,11 +25,9 @@ import net.citizensnpcs.api.ai.event.NavigationCompleteEvent; import net.citizensnpcs.api.ai.event.NavigationReplaceEvent; import net.citizensnpcs.api.ai.event.NavigationStuckEvent; import net.citizensnpcs.api.ai.event.NavigatorCallback; -import net.citizensnpcs.api.astar.pathfinder.BlockExaminer; -import net.citizensnpcs.api.astar.pathfinder.BlockSource; +import net.citizensnpcs.api.astar.pathfinder.DoorExaminer; import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer; -import net.citizensnpcs.api.astar.pathfinder.PathPoint; -import net.citizensnpcs.api.astar.pathfinder.PathPoint.PathCallback; +import net.citizensnpcs.api.astar.pathfinder.SwimmingExaminer; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.util.DataKey; import net.citizensnpcs.util.NMS; @@ -59,6 +51,7 @@ public class CitizensNavigator implements Navigator, Runnable { public CitizensNavigator(NPC npc) { this.npc = npc; + defaultParams.examiner(new SwimmingExaminer(npc)); if (Setting.NEW_PATHFINDER_OPENS_DOORS.asBoolean()) { defaultParams.examiner(new DoorExaminer()); } @@ -383,41 +376,6 @@ public class CitizensNavigator implements Navigator, Runnable { return false; } - public static class DoorExaminer implements BlockExaminer { - @Override - public float getCost(BlockSource source, PathPoint point) { - return 0F; - } - - @Override - public PassableState isPassable(BlockSource source, PathPoint point) { - Material in = source.getMaterialAt(point.getVector()); - if (MinecraftBlockExaminer.isDoor(in)) { - point.addCallback(new DoorOpener()); - return PassableState.PASSABLE; - } - return PassableState.IGNORE; - } - } - - private static class DoorOpener implements PathCallback { - @Override - public void run(NPC npc, Block point, ListIterator path) { - BlockState state = point.getState(); - Door door = (Door) state.getData(); - if (npc.getStoredLocation().distance(point.getLocation()) < 2) { - boolean bottom = !door.isTopHalf(); - Block set = bottom ? point : point.getRelative(BlockFace.DOWN); - state = set.getState(); - door = (Door) state.getData(); - door.setOpen(true); - state.setData(door); - state.update(); - } - } - } - private static final Location STATIONARY_LOCATION = new Location(null, 0, 0, 0); - private static int UNINITIALISED_SPEED = Integer.MIN_VALUE; } diff --git a/main/src/main/java/net/citizensnpcs/npc/ai/EnhancedMovementExaminer.java b/main/src/main/java/net/citizensnpcs/npc/ai/EnhancedMovementExaminer.java index 975c18379..3e242dc38 100644 --- a/main/src/main/java/net/citizensnpcs/npc/ai/EnhancedMovementExaminer.java +++ b/main/src/main/java/net/citizensnpcs/npc/ai/EnhancedMovementExaminer.java @@ -34,7 +34,7 @@ public class EnhancedMovementExaminer implements NeighbourGeneratorBlockExaminer } } } - return null; + return neighbours; } @Override diff --git a/main/src/main/java/net/citizensnpcs/trait/waypoint/GuidedWaypointProvider.java b/main/src/main/java/net/citizensnpcs/trait/waypoint/GuidedWaypointProvider.java index 39b06cbfc..703dfb036 100644 --- a/main/src/main/java/net/citizensnpcs/trait/waypoint/GuidedWaypointProvider.java +++ b/main/src/main/java/net/citizensnpcs/trait/waypoint/GuidedWaypointProvider.java @@ -273,7 +273,7 @@ public class GuidedWaypointProvider implements EnumerableWaypointProvider { return false; } Waypoint target = available.get(Util.getFastRandom().nextInt(available.size())); - plan = ASTAR.runFully(new GuidedGoal(target), new GuidedNode(new Waypoint(npc.getStoredLocation()))); + plan = ASTAR.runFully(new GuidedGoal(target), new GuidedNode(null, new Waypoint(npc.getStoredLocation()))); return plan != null; } } @@ -309,7 +309,8 @@ public class GuidedWaypointProvider implements EnumerableWaypointProvider { private class GuidedNode extends AStarNode { private final Waypoint waypoint; - public GuidedNode(Waypoint waypoint) { + public GuidedNode(GuidedNode parent, Waypoint waypoint) { + super(parent); this.waypoint = waypoint; } @@ -350,7 +351,7 @@ public class GuidedWaypointProvider implements EnumerableWaypointProvider { return Iterables.transform(res, new Function>, AStarNode>() { @Override public AStarNode apply(DistanceResult> arg0) { - return new GuidedNode(arg0.get().getData()); + return new GuidedNode(GuidedNode.this, arg0.get().getData()); } }); }