/
PathFinder.java
37 lines (32 loc) · 1.24 KB
/
PathFinder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package net.aufdemrand.denizen.utilities;
import net.aufdemrand.denizen.objects.dLocation;
import net.citizensnpcs.api.astar.AStarMachine;
import net.citizensnpcs.api.astar.pathfinder.*;
import org.bukkit.Location;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.List;
/**
* TODO: Potentially a separate implementation?
*/
public class PathFinder {
public static AStarMachine ASTAR = AStarMachine.createWithDefaultStorage();
public static List<dLocation> getPath(Location start, Location dest) {
VectorGoal goal = new VectorGoal(dest, 1);
Path plan = (Path) ASTAR.runFully(goal,
new VectorNode(goal, start, new ChunkBlockSource(start, 100), new MinecraftBlockExaminer()),
50000);
if (plan == null || plan.isComplete()) {
return new ArrayList<dLocation>();
}
else {
List<dLocation> path = new ArrayList<dLocation>();
while (!plan.isComplete()) {
Vector v = plan.getCurrentVector();
path.add(new dLocation(start.getWorld(), v.getX(), v.getY(), v.getZ()));
plan.update(null);
}
return path;
}
}
}