Skip to content
This repository was archived by the owner on Jun 1, 2024. It is now read-only.

Entity Controllers | Navigation

GamerCoder edited this page Jan 20, 2023 · 1 revision

Navigation is a complex way of moving an entity. It uses multiple points to move to a final destination.

Why use this over Controllers?

  • Navigation uses multiple points (called "nodes") instead of having a chain of methods, which can be neater.
  • Navigation focuses on simply movement and is optimized to do so.

When use this over Controllers?

  • Large-Scale Entity Movement
  • Pauses between Movement Points

Creating a Path

A NavigationPath is a specific type of Path that contains many NavigationNodes, which are points of Locations that don't require a world.

Here's how to create a path:

import me.gamercoder215.mobchip.bukkit.BukkitBrain;
import me.gamercoder215.mobchip.EntityBrain;
import me.gamercoder215.mobchip.util.Position;
import me.gamercoder215.mobchip.ai.navigation.NavigationPath;
import me.gamercoder215.mobchip.ai.navigation.EntityNavigation;

public class MyPlugin extends JavaPlugin {

    public NavigationPath createPath(Mob m) {
        EntityBrain brain = BukkitBrain.getBrain(m);

        // Creates a new EntityNavigation
        EntityNavigation navigation = brain.createNavigation();

        // Creates and adds a new Node at (100, 64, 128)
        Position point1 = new Position(100, 64, 128);
        navigation.addPoint(point1);

        // Creates and adds a new Node at (-162, 65, -278)
        Position point2 = new Position(-162, 65, -278);
        navigation.addPoint(point2);

        // Creates and adds the final Node at (-178, 77, -300)
        // Final Points need to be explicitly specified
        Position point3 = new Position(-178, 77, -300);
        navigation.setFinalPoint(point3);

        // Because we're going over large distances, we need to specify a large range
        navigation.setRange(500F);

        // Builds the final path containing all points
        NavigationPath path = navigation.buildPath();

        // Advances to the first point
        path.advance();

        // Could have a delay, some dialogue, or anything here...

        // Then advance to the next point
        path.advance();
    }

}

Clone this wiki locally