Skip to content

MoveControl 5.46.0 ​

class · pocketmine\entity\ai\control\MoveControl · source

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 ​

php
public const GROUND_SPEED_FACTOR = 0.98 / (1 - 0.6 * 0.91)

Steady ground speed factor, see class doc.

STATE_DRIVE protected ​

php
protected const STATE_DRIVE = 3

STATE_MOVE_TO protected ​

php
protected const STATE_MOVE_TO = 1

STATE_STRAFE protected ​

php
protected const STATE_STRAFE = 2

STATE_WAIT protected ​

php
protected const STATE_WAIT = 0

Properties ​

$active protected ​

php
protected bool $active

$jump protected ​

php
protected bool $jump

$mob ​

php
public \pocketmine\entity\Mob $mob

$speedMultiplier protected ​

php
protected float $speedMultiplier

$state protected ​

php
protected int $state

$velocityX protected ​

php
protected float $velocityX

Output of tick(): wanted horizontal velocity in blocks per tick.

$velocityZ protected ​

php
protected float $velocityZ

$wantedX protected ​

php
protected float $wantedX

$wantedY protected ​

php
protected float $wantedY

$wantedZ protected ​

php
protected float $wantedZ

Methods ​

__construct() ​

php
public function __construct(\pocketmine\entity\Mob $mob)

consumeJump() ​

php
public function consumeJump() : bool

Returns and clears the jump request.

drive() ​

php
public function drive(float $forward, float $left, float $speed) : void

Moves 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() ​

php
public function getGroundSpeed(float $speedMultiplier) : float

Returns the ground speed in blocks per tick for the mob's movement attribute times the given multiplier.

getSpeedMultiplier() ​

php
public function getSpeedMultiplier() : float

getVelocityX() ​

php
public function getVelocityX() : float

getVelocityY() ​

php
public function getVelocityY() : float

Wanted vertical velocity, only used when MoveControl::isThreeDimensional() is true.

getVelocityZ() ​

php
public function getVelocityZ() : float

getWantedX() ​

php
public function getWantedX() : float

getWantedY() ​

php
public function getWantedY() : float

getWantedZ() ​

php
public function getWantedZ() : float

hasWanted() ​

php
public function hasWanted() : bool

isMoving() ​

php
public function isMoving() : bool

isThreeDimensional() ​

php
public function isThreeDimensional() : bool

Returns 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() ​

php
public function jump() : void

rotlerp() ​

php
public static function rotlerp(float $from, float $to, float $max) : float

Rotates the angle $from towards $to by at most $max degrees, taking the shortest way round.

setWantedPosition() ​

php
public function setWantedPosition(float $x, float $y, float $z, float $speedMultiplier) : void

stop() ​

php
public function stop() : void

strafe() ​

php
public function strafe(float $forward, float $right, float $speedMultiplier) : void

Moves relative to the mob's facing: forward/backward and right/left inputs between -1 and 1.

tick() ​

php
public function tick() : void

tickThreeDimensional() protected ​

php
protected function tickThreeDimensional(float $speed, float &$velocityY) : void

Three-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() ​

php
public static function wrapDegrees(float $degrees) : float

Wraps an angle to [-180, 180).

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.