Mob 5.46.0
Extends Living
A living entity driven by server-side AI: goals (GoalSelector), pathfinding (PathNavigator), and move/look controls. Subclasses register their goals in Mob::registerGoals().
Each tick the running goals and the controls run (cheap); starting new goals is evaluated every Mob::GOAL_EVALUATION_INTERVAL ticks, staggered by entity ID and limited server-wide by AiBudget. Mobs with no player within Mob::ACTIVATION_RANGE blocks freeze their AI.
Constants
ACTIVATION_RANGE
public const ACTIVATION_RANGE = 64Mobs farther than this from every player don't run AI (vanilla simulation distance: 4 chunks).
GOAL_EVALUATION_INTERVAL
public const GOAL_EVALUATION_INTERVAL = 3Ticks between two evaluations of the goals that may start. Goals with a per-tick chance to start scale it by this value.
LEASH_BREAK_DISTANCE
public const LEASH_BREAK_DISTANCE = 10.0Leads break beyond this distance, pull the mob beyond the elastic one, and make it follow beyond the last.
LEASH_ELASTIC_DISTANCE
public const LEASH_ELASTIC_DISTANCE = 6.0LEASH_FOLLOW_DISTANCE
public const LEASH_FOLLOW_DISTANCE = 3.0TAG_LEASH_FENCE
public const TAG_LEASH_FENCE = "LeashFence"TAG_LEASH_PLAYER
public const TAG_LEASH_PLAYER = "LeashHolderUUID"TAG_PERSISTENT
public const TAG_PERSISTENT = "Persistent"Properties
$attackTarget protected
protected ?\pocketmine\entity\Living $attackTarget$boostTicks protected
protected int $boostTicksTicks of boost (carrot or warped fungus on a stick) left.
$despawnFarTicks protected
protected int $despawnFarTicksTicks spent beyond the random despawn distance (see MobDespawner).
$goalSelector protected
protected \pocketmine\entity\ai\goal\GoalSelector $goalSelector$headYaw protected
protected float $headYaw$lastAttackedTick protected
protected int $lastAttackedTick$lastAttacker protected
protected ?\pocketmine\entity\Living $lastAttacker$lastHurtByPlayer protected
protected ?\pocketmine\player\Player $lastHurtByPlayer$lastHurtByPlayerTick protected
protected int $lastHurtByPlayerTick$lookControl protected
protected \pocketmine\entity\ai\control\LookControl $lookControl$moveControl protected
protected \pocketmine\entity\ai\control\MoveControl $moveControl$navigation protected
protected \pocketmine\entity\ai\navigation\PathNavigator $navigation$noActionTicks protected
protected int $noActionTicksTicks the mob has been without a player nearby, used for despawning.
$persistent protected
protected bool $persistentPersistent mobs never despawn (spawn eggs, bred, named, picked up items...).
$riderInput protected
protected ?\pocketmine\entity\riding\RiderInput $riderInput$sensing protected
protected \pocketmine\entity\ai\sensing\Sensing $sensing$targetSelector protected
protected \pocketmine\entity\ai\goal\GoalSelector $targetSelectorMethods
attack()
public function attack(\pocketmine\event\entity\EntityDamageEvent $source) : voidattackMelee()
public function attackMelee(\pocketmine\entity\Living $target, float $baseDamage) : boolHits the target in melee: base damage scaled by difficulty (vanilla: easy min(d/2+1, d), hard d*1.5), knockback and arm swing.
broadcastMovement() protected
protected function broadcastMovement(bool $teleport = false) : voidSends the movement to the viewers, less often to the ones far away (see mobs.movement-broadcast in pocketmine.yml): like players, every moving mob would otherwise send a packet to every viewer every tick. Teleports and ridden mobs always go to everyone.
canBeSteeredBy()
public function canBeSteeredBy(\pocketmine\player\Player $rider) : boolReturns whether the given player, riding on the first seat, steers this mob (vanilla: saddled horses, pigs ridden with a carrot on a stick...). Mobs that can't be steered keep their own AI when ridden.
canDespawn()
public function canDespawn() : boolReturns whether the mob may be despawned when far from players.
checkDespawn() protected
protected function checkDespawn() : boolCalled every 20 ticks for mobs which may despawn (Mob::canDespawn()). Returns whether the mob should despawn now (vanilla distance rules, see MobDespawner).
consumeHeldItem() protected
protected function consumeHeldItem(\pocketmine\player\Player $player, int $count = 1) : voidRemoves items from the stack in the player's hand (not in creative).
createMoveControl() protected
protected function createMoveControl() : \pocketmine\entity\ai\control\MoveControlCreates the move control: walking by default, \pocketmine\entity\ai\control\FlyingMoveControl or \pocketmine\entity\ai\control\SwimmingMoveControl for flying and swimming mobs.
createNavigation() protected
protected function createNavigation() : \pocketmine\entity\ai\navigation\PathNavigatordamageHeldItem() protected
protected function damageHeldItem(\pocketmine\player\Player $player) : voidUses one durability of the tool in the player's hand (vanilla interact "hurt_item", e.g. shears taking a saddle off), not in creative.
destroyCycles() protected
protected function destroyCycles() : voidentityBaseTick() protected
protected function entityBaseTick(int $tickDiff = 1) : boolexchangeHeldItem() protected
protected function exchangeHeldItem(\pocketmine\player\Player $player, \pocketmine\item\Item $result) : voidReplaces one item of the stack in the player's hand with the result (e.g. bucket -> milk bucket).
findWanderPos()
public function findWanderPos(int $horizontal, int $vertical, ?\pocketmine\math\Vector3 $awayFrom = null) : ?\pocketmine\math\Vector3Returns a random point to wander or flee to (used by the stroll and panic goals), or null if none was found. Walking mobs pick a standable block (its centre); swimming and flying mobs override this to pick water or air.
getActorProperty()
public function getActorProperty(string $name) : intReturns the encoded value of an actor property (enum index, 0/1 for booleans).
getAiTick()
public function getAiTick() : intReturns the server tick of the mob's current (or last) update.
getAttackTarget()
public function getAttackTarget() : ?\pocketmine\entity\LivinggetBoostItemTypeId() protected
protected function getBoostItemTypeId() : ?intReturns the item boosting this mob when used by its rider (vanilla boostable component), or null.
getBoostProperties() protected
protected function getBoostProperties() : arrayReturns [boost duration in ticks, durability used] (vanilla boostable component).
getBoostSpeedMultiplier() protected
protected function getBoostSpeedMultiplier() : floatgetGoalSelector()
public function getGoalSelector() : \pocketmine\entity\ai\goal\GoalSelectorgetHeadYaw()
public function getHeadYaw() : floatgetInteractButtonText()
public function getInteractButtonText(\pocketmine\player\Player $player) : stringThe interaction button of a mob the player may get on, or of an item use (see Mob::getItemInteractButtonText()).
getItemInteractButtonText() protected
protected function getItemInteractButtonText(\pocketmine\player\Player $player, \pocketmine\item\Item $item) : ?stringReturns the interaction button for using the held item on this mob (saddling...), or null if none.
getLastAttackedTick()
public function getLastAttackedTick() : intgetLastAttacker()
public function getLastAttacker() : ?\pocketmine\entity\LivinggetLookControl()
public function getLookControl() : \pocketmine\entity\ai\control\LookControlgetLootingLevel()
public function getLootingLevel() : intReturns the Looting level of the weapon of the player who last hit the mob, if it was a recent player kill.
getMoveControl()
public function getMoveControl() : \pocketmine\entity\ai\control\MoveControlgetNavigation()
public function getNavigation() : \pocketmine\entity\ai\navigation\PathNavigatorgetNetworkSyncedProperties()
public function getNetworkSyncedProperties() : \pocketmine\network\mcpe\protocol\types\entity\PropertySyncDatagetRiddenInput() protected
protected function getRiddenInput(\pocketmine\entity\riding\RiderInput $input) : arrayReturns the forward and left movement inputs (-1 to 1) of a steered mob. By default the rider's move vector, with slower backwards and sideways movement (vanilla horses).
getRiddenSpeed() protected
protected function getRiddenSpeed(\pocketmine\player\Player $rider) : floatReturns the speed of the mob in blocks per tick when steered by its rider, before boosts.
getRideInteractText() protected
protected function getRideInteractText() : stringReturns the interaction button for getting on this mob (vanilla rideable interact_text).
getSensing()
public function getSensing() : \pocketmine\entity\ai\sensing\SensinggetSteeringPlayer()
public function getSteeringPlayer() : ?\pocketmine\player\PlayerReturns the player steering this mob: its rider, if it may steer the mob and sent input recently.
getTargetSelector()
public function getTargetSelector() : \pocketmine\entity\ai\goal\GoalSelectorhandleClientVehicleMovement()
public function handleClientVehicleMovement(\pocketmine\player\Player $rider, \pocketmine\math\Vector3 $pos, float $yaw, float $pitch) : boolCalled when the client of the rider moved this mob itself (client-predicted vehicles). Accepts the movement if the rider steers this mob, the distance is plausible and the mob doesn't end up inside blocks.
handleRiderInput()
public function handleRiderInput(\pocketmine\player\Player $rider, \pocketmine\entity\riding\RiderInput $input) : voidCalled every tick with the input of the player riding on the first seat. The mob follows it when the player can steer it (see Mob::canBeSteeredBy()).
handleRiderItemUse()
public function handleRiderItemUse(\pocketmine\player\Player $rider, \pocketmine\item\Item $item) : boolCalled when the rider steering this mob uses the held item: a boost item (carrot or warped fungus on a stick) speeds the mob up and loses durability (the stick turns into a fishing rod when it breaks). Returns whether the item was used.
hasMovementUpdate()
public function hasMovementUpdate() : boolinitEntity() protected
protected function initEntity(\pocketmine\nbt\tag\CompoundTag $nbt) : voidisBoosting()
public function isBoosting() : boolisDrivenByRiderClient() protected
protected function isDrivenByRiderClient() : boolReturns whether the client of a rider steering this mob drives it with its own movement controls (vanilla input_ground_controlled / free camera controlled mounts: horses, camels, nautiluses, happy ghasts).
isInContactWithWater()
public function isInContactWithWater() : boolReturns whether the mob touches water: in it, under it or in the rain (Bedrock filter in_contact_with_water). Callers should not check this every tick (the rain part looks up the column above the mob).
isInWater()
public function isInWater() : boolReturns whether the mob's feet are in water.
isMovedByClient()
public function isMovedByClient() : boolReturns whether the client of the rider is moving this mob itself (client-predicted vehicles like horses): the server then doesn't move it and doesn't send its movement back to that client.
isPersistent()
public function isPersistent() : boollootingBonus() protected
protected function lootingBonus(int $perLevel = 1) : intVanilla "looting_enchant" loot function: adds 0 to $perLevel extra items per Looting level.
onDeath() protected
protected function onDeath() : voidonDispose() protected
protected function onDispose() : voidonFrozenUpdate()
public function onFrozenUpdate(int $currentTick) : boolonInteract()
public function onInteract(\pocketmine\player\Player $player, \pocketmine\math\Vector3 $clickPos) : boolonInteractWithItem() protected
protected function onInteractWithItem(\pocketmine\player\Player $player, \pocketmine\item\Item $item) : boolCalled when a player interacts with the mob holding the given item. Returns whether something happened.
playAmbientSound() protected
protected function playAmbientSound() : voidplayMobSound()
public function playMobSound(string $sound, int $extraData = -1) : voidregisterGoals() protected
abstract protected function registerGoals() : voidAdds the mob's goals to Mob::$goalSelector and Mob::$targetSelector.
resyncClientVehicle()
public function resyncClientVehicle(\pocketmine\player\Player $rider) : voidSends the mob's position to the client of its rider, which moved it somewhere it was not allowed to go.
saveNBT()
public function saveNBT() : \pocketmine\nbt\tag\CompoundTagscaleDamageForDifficulty()
public static function scaleDamageForDifficulty(float $damage, int $difficulty) : floatsetActorProperty()
public function setActorProperty(string $name, int|bool|string $value) : voidSets an actor property of this mob (e.g. "minecraft:armadillo_state"), registered for its type in EntityPropertyRegistry. Enum properties take the value name, booleans a bool.
setAttackTarget()
public function setAttackTarget(?\pocketmine\entity\Living $target) : voidsetNameTag()
public function setNameTag(string $name) : voidsetPersistent()
public function setPersistent(bool $persistent) : voidsetRotation()
public function setRotation(float $yaw, float $pitch) : voidsteer() protected
protected function steer(\pocketmine\player\Player $rider, \pocketmine\entity\riding\RiderInput $input) : voidMoves the mob following the input of the player steering it (ground mobs: towards the rider's look direction with Mob::getRiddenInput(), at Mob::getRiddenSpeed()). Flying and swimming steered mobs override this.
syncNetworkData() protected
protected function syncNetworkData(\pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection $properties) : voidtickAi() protected
protected function tickAi(int $currentTick) : voidtryChangeMovement() protected
protected function tryChangeMovement() : voidtryRide() protected
protected function tryRide(\pocketmine\player\Player $player) : boolMakes the player ride this mob after interacting with it, unless sneaking. Returns whether it got on.
updateActivation() protected
protected function updateActivation() : boolReturns whether a player is close enough for the mob to run its AI. Called every 20 ticks.
updateMovement() protected
protected function updateMovement(bool $teleport = false) : voidwasRecentlyHitByPlayer()
public function wasRecentlyHitByPlayer() : boolReturns whether the last damage was dealt by a player recently enough for a death to count as a player kill (vanilla: player-only loot and experience).
