Skip to content
Benjamin Sommerfeld edited this page Jan 30, 2026 · 6 revisions

So you fired off a request. Now the PathfindingSearch has finished. This object tells you if you reached the destination or if you just hit a wall.


Did we make it?

Don't just blindly assume success. Always check the PathState.

pathfindingResult.ifPresent(result -> {
    
    // 1. The Happy Path
    if (result.successful()) {
        System.out.println("Success. Length: " + path.length());
    }

    // 2. The "Participation Trophy" (Fallback)
    if (result.hasFallenBack()) {
        System.out.println("Couldn't reach target, but here is the closest point.");
    }

    Path path = result.getPath();
    moveEntity(path);

}).orElse(result -> {

    // 3. Total Failure
    System.err.println("Gave up. Reason: " + result.state());

});

The State of Failure

The PathState enum tells you why something happened.

  • FOUND: Success. We made it.

  • FAILED: Impossible. There is no valid path between A and B.

  • MAX_ITERATIONS_REACHED: Timeout. The search took too long and was killed to save your CPU.

  • LENGTH_LIMITED: Too far. The path exists, but it's longer than your maxLength config allowed.

  • FALLBACK: "At least I tried." We couldn't reach the target, but found the closest reachable node.

  • ABORTED: Rage quit. You called .abort() externally.


The Path Object

The Path is just an ordered list of PathPosition (x, y, z). It implements Iterable, so just loop over it.

Path path = result.getPath();

for (PathPosition pos : path) {
    // Move your entity here
    entity.teleport(pos.getX(), pos.getY(), pos.getZ());
}

Clone this wiki locally