A mount controller is a per-entity Modeled Entity movement controller that is required when mounting an entity to a model. By default, Model Engine provides 4 common controllers, but you can add your own to create custom controlling behavior. Read this page for more information on the default controllers.
Creating a controller class
All controller class must implement MountController
class, but you can also extend the AbstractMountController
instead, which provides implementations on some basic and generic functionalities. In this example, we will
use AbstractMountController
.
public class CustomMountController extends AbstractMountController {
// Type class used to specify the controller when mounting entity
// NEVER SUPPLY A STATIC INSTANCE
public static final MountControllerType CUSTOM = new MountControllerType(CustomMountController::new);
public CustomMountController(Entity entity, Mount mount) {
super(entity, mount);
}
@Override
public void updateDriverMovement(MoveController controller, ActiveModel model) {
// Update function for driver
}
@Override
public void updatePassengerMovement(MoveController controller, ActiveModel model) {
// Update function for passengers
}
}
Using MoveController
The supplied MoveController
object is a wrapper for the NMS MoveControl
class. It contains numerous functions useful
for controlling the entity, many of which calls back directly to the base NMS method.
Getting Inputs
Inputs are updated every movement tick, and can be obtained through getInput()
method. The returned object contains
WASD, Jump and Sneak inputs.
Caveats
In order for this system to work on most entities and have the movements be calculated correctly, while also altering Minecraft's default movement handling code as little as possible, the system will not work under these conditions:
- The base entity is not a
Mob
(so armor stands will not work) - The base entity has no AI
- The base entity never ticks
Using the controller
Similar to mounting with default controllers, you mount with your own MountControllerType
.
ActiveModel model=...
model.getMountManager().ifPresent(mountManager -> {
mountManager.mountDriver(entity, CustomMountController.CUSTOM);
});
Registering the controller
While technically optional, it is generally advised to register your custom controller into
the MountControllerTypeRegistry
as this will allow you to use the controller with MythicMobs as well.
// On plugin start-up
ModelEngineAPI.getMountControllerTypeRegistry().register("custom_controller", CustomMountController.CUSTOM);