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

Entity Controllers

Gregory Mitchell edited this page May 29, 2024 · 2 revisions

Entity Controllers are a simple way of controlling an entity. You can make them move to a certain location, or look at something else.

Here's an example:

import me.gamercoder215.mobchip.bukkit.BukkitBrain;
import me.gamercoder215.mobchip.EntityBrain;
import me.gamercoder215.mobchip.ai.controller.EntityController;

// Bukkit Imports...

public class MyPlugin extends JavaPlugin {

    public void doActions(Mob m) {
        EntityBrain brain = BukkitBrain.getBrain(m);

        EntityController controller = brain.getController();
        Location target = [...]

        // EntityController has chaining methods, so you can call more than one.
        controller.jump().jump().moveTo(target); // Jumps twice, moves to a location target.
    }

}

Relative Movement

EntityController features two movement methods: moveTo and naturalMoveTo. moveTo is used to go to an absolute location. In contrast naturalMoveTo is used to move to a position relative to the entity.

Differences between the two:

  • moveTo is handled by the internal MoveController, while naturalMoveTo is handled by the entity class
  • moveTo can accept speed modifiers
  • naturalMoveTo can simulate different types of movement (e.g. Entity/Piston Collisions)
  • naturalMoveTo uses more accurate entity pathfinding

Here is an example using naturalMoveTo:

import me.gamercoder215.mobchip.bukkit.BukkitBrain;
import me.gamercoder215.mobchip.EntityBrain;
import me.gamercoder215.mobchip.ai.controller.EntityController;

// Bukkit Imports...

public class MyPlugin extends JavaPlugin {

    public void moveNaturally(Mob m) {
        EntityBrain brain = BukkitBrain.getBrain(m);

        EntityController controller = brain.getController();

        // NaturalMoveType.SELF is the default, saying it moved on its own
        controller.naturalMoveTo(1, 0, 3, NaturalMoveType.SELF); // Move +1 in the X direction, +3 in the Z direction
    }

}