MoveControl 5.46.0
Turns a wanted position (or strafing input) into the horizontal velocity the mob walks with, applied by Mob during its movement update, and decides when to jump.
Speeds follow vanilla: a mob with movement attribute s walking with speed multiplier m reaches a ground speed of (s * m)^2 * 2.1586 blocks per tick, the steady state of Java's travel() on a block with friction 0.6. Mob::setSpeed() sets both the speed and the forward input to s * m, aiStep() scales the input by 0.98 (INPUT_FRICTION), getFrictionInfluencedSpeed() returns the speed unchanged for friction <= 0.6, and the velocity keeps 0.6 * 0.91 of itself every tick: the step per tick settles at 0.98 * (s * m)^2 / (1 - 0.546).
Constants
GROUND_SPEED_FACTOR
public const GROUND_SPEED_FACTOR = 0.98 / (1 - 0.6 * 0.91)Steady ground speed factor, see class doc.
STATE_DRIVE protected
protected const STATE_DRIVE = 3STATE_MOVE_TO protected
protected const STATE_MOVE_TO = 1STATE_STRAFE protected
protected const STATE_STRAFE = 2STATE_WAIT protected
protected const STATE_WAIT = 0Properties
$active protected
protected bool $active$jump protected
protected bool $jump$mob
public \pocketmine\entity\Mob $mob$speedMultiplier protected
protected float $speedMultiplier$state protected
protected int $state$velocityX protected
protected float $velocityXOutput of tick(): wanted horizontal velocity in blocks per tick.
$velocityZ protected
protected float $velocityZ$wantedX protected
protected float $wantedX$wantedY protected
protected float $wantedY$wantedZ protected
protected float $wantedZMethods
__construct()
public function __construct(\pocketmine\entity\Mob $mob)consumeJump()
public function consumeJump() : boolReturns and clears the jump request.
drive()
public function drive(float $forward, float $left, float $speed) : voidMoves at the given speed in blocks per tick relative to the mob's facing, with forward/backward and left/right inputs between -1 and 1, stepping up blocks it bumps into. Used for mobs steered by their rider: the input must be renewed every tick.
getGroundSpeed()
public function getGroundSpeed(float $speedMultiplier) : floatReturns the ground speed in blocks per tick for the mob's movement attribute times the given multiplier.
getSpeedMultiplier()
public function getSpeedMultiplier() : floatgetVelocityX()
public function getVelocityX() : floatgetVelocityY()
public function getVelocityY() : floatWanted vertical velocity, only used when MoveControl::isThreeDimensional() is true.
getVelocityZ()
public function getVelocityZ() : floatgetWantedX()
public function getWantedX() : floatgetWantedY()
public function getWantedY() : floatgetWantedZ()
public function getWantedZ() : floathasWanted()
public function hasWanted() : boolisMoving()
public function isMoving() : boolisThreeDimensional()
public function isThreeDimensional() : boolReturns whether the mob currently moves in three dimensions (flying, or swimming in water): the velocity output includes a vertical component and the mob is not pulled down by gravity while moving.
jump()
public function jump() : voidrotlerp()
public static function rotlerp(float $from, float $to, float $max) : floatRotates the angle $from towards $to by at most $max degrees, taking the shortest way round.
setWantedPosition()
public function setWantedPosition(float $x, float $y, float $z, float $speedMultiplier) : voidstop()
public function stop() : voidstrafe()
public function strafe(float $forward, float $right, float $speedMultiplier) : voidMoves relative to the mob's facing: forward/backward and right/left inputs between -1 and 1.
tick()
public function tick() : voidtickThreeDimensional() protected
protected function tickThreeDimensional(float $speed, float &$velocityY) : voidThree-dimensional movement towards the wanted position (flying, swimming) at the given speed in blocks per tick. Strafing input is ignored. Sets the vertical velocity in $velocityY.
wrapDegrees()
public static function wrapDegrees(float $degrees) : floatWraps an angle to [-180, 180).
