From e61af2d351a4ee516b2c1b0b5cbb751aea7234c9 Mon Sep 17 00:00:00 2001 From: fullwall Date: Sat, 19 Jan 2019 15:31:38 +0800 Subject: [PATCH] Add fallback wander goal --- .../waypoint/WanderWaypointProvider.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java b/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java index a09190e4a..e7685a7c3 100644 --- a/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java +++ b/main/src/main/java/net/citizensnpcs/trait/waypoint/WanderWaypointProvider.java @@ -13,12 +13,14 @@ import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.metadata.FixedMetadataValue; +import com.google.common.base.Function; import com.google.common.base.Supplier; import com.google.common.collect.ForwardingList; import com.google.common.collect.Lists; import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.ai.goals.WanderGoal; +import net.citizensnpcs.api.astar.pathfinder.MinecraftBlockExaminer; import net.citizensnpcs.api.command.CommandContext; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.persistence.Persist; @@ -29,7 +31,7 @@ import net.citizensnpcs.api.util.cuboid.QuadTree; import net.citizensnpcs.util.Messages; import net.citizensnpcs.util.Util; -public class WanderWaypointProvider implements WaypointProvider, Supplier { +public class WanderWaypointProvider implements WaypointProvider, Supplier, Function { private WanderGoal currentGoal; private NPC npc; private volatile boolean paused; @@ -41,6 +43,24 @@ public class WanderWaypointProvider implements WaypointProvider, Supplier minDist) { + minDist = d; + closestCentre = centre; + } + } + if (closestCentre != null) { + // TODO: should find closest edge block that is valid + return MinecraftBlockExaminer.findValidLocation(closestCentre, xrange, yrange); + } + return null; + } + @Override public WaypointEditor createEditor(final CommandSender sender, CommandContext args) { return new WaypointEditor() { @@ -184,7 +204,8 @@ public class WanderWaypointProvider implements WaypointProvider, Supplier