[LIB] MCPath - A Custom A* Pathfinding Library

Discussion in 'Resources' started by Jnorr44, Jan 27, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Jnorr44

    MCPath
    (see below to get it!)



    MCPath allows a path to be created in the MC world using A* pathfinding (hopefully soon fringe pathfinding as well). It uses custom pathfinder goals to determine which nodes to avoid, which to prefer, and really, where to go in general. So, whether your looking to make a mob move to a target, or to direct a player along their green line to financial happiness (Fidelity reference), MCPath is the library for you!

    Create a list of goals:
    Code:java
    1. ArrayList<PathfinderGoal> goals = new ArrayList<PathfinderGoal>() {
    2. {
    3. add(new PathfinderGoal() {
    4. @Override public PathNode transform(List<PathNode> navigated, PathNode node) {
    5. //set node.H to Double.NEGATIVE_INFINITY to prefer, or Double.POSITIVE_INFINITY to avoid
    6. return node;
    7. }
    8. });
    9. }
    10. };


    Calculate a path:
    Code:java
    1. Path path = new Pathfinder(start, finish, goals).calculate();
    2. //Where start and finish are locations


    Have a mob follow the path:
    Code:java
    1. Bukkit.getScheduler().scheduleSyncRepeatingTask(instance, new Runnable() {
    2. @Override public void run() {
    3. nodeNumber++;
    4. entity/*your mob*/.teleport(path.getNode(nodeNumber));
    5. //This will teleport 1 block per tick, probably too fast for practical use
    6. }
    7. }, 1, 1);


    >>>GET MCPATH <<<

    Also be sure to check out MCShot, a custom realistic projectile library.​
     
    Skyost and Yonas like this.
  2. Offline

    Yonas

    just awesome :)
     
  3. Offline

    darkbro100

    Make them target players and such? Jnorr44
     
  4. Offline

    Jnorr44

    It's been in the works for a while, don't know when I will complete it.
     
  5. Offline

    ResultStatic

    Jnorr44 i used the nms pathfinding system and i think you will get smoother results with it, but its a bit complicated getting into, it has a learning curve. i created custom pathfinders for my player npcs that find certain blocks and attack a player in the range specified.
     
  6. Offline

    Jnorr44

    The point is to avoid that system, it requires updates every few versions, and doesn't provide much access.
     
Thread Status:
Not open for further replies.

Share This Page