第四章 运动控制器 - 处理实体运动的核心
author: daoge_cmd
The translation made by AzaleeX contributed to the PowerNukkitX documentation
1.0 Control entity movement
Motion controllers are used to control the behavior of entities, such as the specific implementation of movement, jumping, attacking, and so on.
For different entities, different controllers can be provided to achieve special implementations of the above behaviors.
1.1 Workflow
The controller is very simple and its interface has only one method:
control
method will be called once per gt to handle entity movement
1.2 Control controller via operating memory
The controller does its job by reading a specific memory
Take the example of a sheep, which uses two controllersLookController
,WalkController
The following memories are used:
MemoryType<Vector3> LOOK_TARGET = new MemoryType<>("minecraft:look_target");
MemoryType<Vector3> MOVE_TARGET = new MemoryType<>("minecraft:move_target");
MemoryType<Vector3> MOVE_DIRECTION_START = new MemoryType<>("minecraft:move_direction_start");
MemoryType<Vector3> MOVE_DIRECTION_END = new MemoryType<>("minecraft:move_direction_end");
MemoryType<Boolean> SHOULD_UPDATE_MOVE_DIRECTION = new MemoryType<>("minecraft:should_update_move_direction", false);
MemoryType<Boolean> ENABLE_PITCH = new MemoryType<>("minecraft:enable_pitch", true);
1.3 Introduction: Several controllers by default
The core already comes with several controllers, which in most cases you can use directly:
- WalkController for walking creatures on land, controlling the movement of entities
- SpaceMoveController for flying/water creatures, control entity movement
- LookController controls the yaw and pitch of the entity's body/head
© PowerNukkitX Dev team