Search in sources :

Example 1 with PathingResult

use of com.adamki11s.pathing.PathingResult in project CyanBot by XjCyan1de.

the class MoveTask method runPathing.

public void runPathing(final Location start, final Location end, final int range) {
    try {
        // create our pathfinder
        AStar path = new AStar(bot.getWorld(), start, end, range);
        // get the list of nodes to walk to as a Tile object
        ArrayList<Tile> route = path.iterate();
        // get the result of the path trace
        PathingResult result = path.getPathingResult();
        switch(result) {
            case SUCCESS:
                // Path was successful. Do something here.
                moveAlong(start, route);
                System.out.println("Path was found! :D");
                break;
            case NO_PATH:
                // No path found, throw error.
                System.out.println("No path found!");
                // c.chat.sendMessage("No path was found :(");
                break;
            default:
                // c.chat.sendMessage("Well... appearently we didn't find a path and we did... at the same time");
                break;
        }
    } catch (AStar.InvalidPathException e) {
        // InvalidPathException will be thrown if start or end block is air
        if (e.isEndNotSolid()) {
        // System.out.println("End block is not walkable");
        // c.chat.sendMessage("Unable to walk on the block you are standing on.");
        }
        if (e.isStartNotSolid()) {
            System.out.println("Start block is not walkable");
        }
    }
}
Also used : PathingResult(com.adamki11s.pathing.PathingResult) AStar(com.adamki11s.pathing.AStar) Tile(com.adamki11s.pathing.Tile)

Aggregations

AStar (com.adamki11s.pathing.AStar)1 PathingResult (com.adamki11s.pathing.PathingResult)1 Tile (com.adamki11s.pathing.Tile)1