Skip to content

Mob 5.46.0 ​

abstract class · pocketmine\entity\Mob · source

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 ​

php
public const ACTIVATION_RANGE = 64

Mobs farther than this from every player don't run AI (vanilla simulation distance: 4 chunks).

GOAL_EVALUATION_INTERVAL ​

php
public const GOAL_EVALUATION_INTERVAL = 3

Ticks 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 ​

php
public const LEASH_BREAK_DISTANCE = 10.0

Leads break beyond this distance, pull the mob beyond the elastic one, and make it follow beyond the last.

LEASH_ELASTIC_DISTANCE ​

php
public const LEASH_ELASTIC_DISTANCE = 6.0

LEASH_FOLLOW_DISTANCE ​

php
public const LEASH_FOLLOW_DISTANCE = 3.0

TAG_LEASH_FENCE ​

php
public const TAG_LEASH_FENCE = "LeashFence"

TAG_LEASH_PLAYER ​

php
public const TAG_LEASH_PLAYER = "LeashHolderUUID"

TAG_PERSISTENT ​

php
public const TAG_PERSISTENT = "Persistent"

Properties ​

$attackTarget protected ​

php
protected ?\pocketmine\entity\Living $attackTarget

$boostTicks protected ​

php
protected int $boostTicks

Ticks of boost (carrot or warped fungus on a stick) left.

$despawnFarTicks protected ​

php
protected int $despawnFarTicks

Ticks spent beyond the random despawn distance (see MobDespawner).

$goalSelector protected ​

php
protected \pocketmine\entity\ai\goal\GoalSelector $goalSelector

$headYaw protected ​

php
protected float $headYaw

$lastAttackedTick protected ​

php
protected int $lastAttackedTick

$lastAttacker protected ​

php
protected ?\pocketmine\entity\Living $lastAttacker

$lastHurtByPlayer protected ​

php
protected ?\pocketmine\player\Player $lastHurtByPlayer

$lastHurtByPlayerTick protected ​

php
protected int $lastHurtByPlayerTick

$lookControl protected ​

php
protected \pocketmine\entity\ai\control\LookControl $lookControl

$moveControl protected ​

php
protected \pocketmine\entity\ai\control\MoveControl $moveControl

$navigation protected ​

php
protected \pocketmine\entity\ai\navigation\PathNavigator $navigation

$noActionTicks protected ​

php
protected int $noActionTicks

Ticks the mob has been without a player nearby, used for despawning.

$persistent protected ​

php
protected bool $persistent

Persistent mobs never despawn (spawn eggs, bred, named, picked up items...).

$riderInput protected ​

php
protected ?\pocketmine\entity\riding\RiderInput $riderInput

$sensing protected ​

php
protected \pocketmine\entity\ai\sensing\Sensing $sensing

$targetSelector protected ​

php
protected \pocketmine\entity\ai\goal\GoalSelector $targetSelector

Methods ​

attack() ​

php
public function attack(\pocketmine\event\entity\EntityDamageEvent $source) : void

attackMelee() ​

php
public function attackMelee(\pocketmine\entity\Living $target, float $baseDamage) : bool

Hits 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 ​

php
protected function broadcastMovement(bool $teleport = false) : void

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

php
public function canBeSteeredBy(\pocketmine\player\Player $rider) : bool

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

php
public function canDespawn() : bool

Returns whether the mob may be despawned when far from players.

checkDespawn() protected ​

php
protected function checkDespawn() : bool

Called every 20 ticks for mobs which may despawn (Mob::canDespawn()). Returns whether the mob should despawn now (vanilla distance rules, see MobDespawner).

consumeHeldItem() protected ​

php
protected function consumeHeldItem(\pocketmine\player\Player $player, int $count = 1) : void

Removes items from the stack in the player's hand (not in creative).

createMoveControl() protected ​

php
protected function createMoveControl() : \pocketmine\entity\ai\control\MoveControl

Creates the move control: walking by default, \pocketmine\entity\ai\control\FlyingMoveControl or \pocketmine\entity\ai\control\SwimmingMoveControl for flying and swimming mobs.

createNavigation() protected ​

php
protected function createNavigation() : \pocketmine\entity\ai\navigation\PathNavigator

damageHeldItem() protected ​

php
protected function damageHeldItem(\pocketmine\player\Player $player) : void

Uses 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 ​

php
protected function destroyCycles() : void

entityBaseTick() protected ​

php
protected function entityBaseTick(int $tickDiff = 1) : bool

exchangeHeldItem() protected ​

php
protected function exchangeHeldItem(\pocketmine\player\Player $player, \pocketmine\item\Item $result) : void

Replaces one item of the stack in the player's hand with the result (e.g. bucket -> milk bucket).

findWanderPos() ​

php
public function findWanderPos(int $horizontal, int $vertical, ?\pocketmine\math\Vector3 $awayFrom = null) : ?\pocketmine\math\Vector3

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

php
public function getActorProperty(string $name) : int

Returns the encoded value of an actor property (enum index, 0/1 for booleans).

getAiTick() ​

php
public function getAiTick() : int

Returns the server tick of the mob's current (or last) update.

getAttackTarget() ​

php
public function getAttackTarget() : ?\pocketmine\entity\Living

getBoostItemTypeId() protected ​

php
protected function getBoostItemTypeId() : ?int

Returns the item boosting this mob when used by its rider (vanilla boostable component), or null.

getBoostProperties() protected ​

php
protected function getBoostProperties() : array

Returns [boost duration in ticks, durability used] (vanilla boostable component).

getBoostSpeedMultiplier() protected ​

php
protected function getBoostSpeedMultiplier() : float

getGoalSelector() ​

php
public function getGoalSelector() : \pocketmine\entity\ai\goal\GoalSelector

getHeadYaw() ​

php
public function getHeadYaw() : float

getInteractButtonText() ​

php
public function getInteractButtonText(\pocketmine\player\Player $player) : string

The interaction button of a mob the player may get on, or of an item use (see Mob::getItemInteractButtonText()).

getItemInteractButtonText() protected ​

php
protected function getItemInteractButtonText(\pocketmine\player\Player $player, \pocketmine\item\Item $item) : ?string

Returns the interaction button for using the held item on this mob (saddling...), or null if none.

getLastAttackedTick() ​

php
public function getLastAttackedTick() : int

getLastAttacker() ​

php
public function getLastAttacker() : ?\pocketmine\entity\Living

getLookControl() ​

php
public function getLookControl() : \pocketmine\entity\ai\control\LookControl

getLootingLevel() ​

php
public function getLootingLevel() : int

Returns the Looting level of the weapon of the player who last hit the mob, if it was a recent player kill.

getMoveControl() ​

php
public function getMoveControl() : \pocketmine\entity\ai\control\MoveControl

getNavigation() ​

php
public function getNavigation() : \pocketmine\entity\ai\navigation\PathNavigator

getNetworkSyncedProperties() ​

php
public function getNetworkSyncedProperties() : \pocketmine\network\mcpe\protocol\types\entity\PropertySyncData

getRiddenInput() protected ​

php
protected function getRiddenInput(\pocketmine\entity\riding\RiderInput $input) : array

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

php
protected function getRiddenSpeed(\pocketmine\player\Player $rider) : float

Returns the speed of the mob in blocks per tick when steered by its rider, before boosts.

getRideInteractText() protected ​

php
protected function getRideInteractText() : string

Returns the interaction button for getting on this mob (vanilla rideable interact_text).

getSensing() ​

php
public function getSensing() : \pocketmine\entity\ai\sensing\Sensing

getSteeringPlayer() ​

php
public function getSteeringPlayer() : ?\pocketmine\player\Player

Returns the player steering this mob: its rider, if it may steer the mob and sent input recently.

getTargetSelector() ​

php
public function getTargetSelector() : \pocketmine\entity\ai\goal\GoalSelector

handleClientVehicleMovement() ​

php
public function handleClientVehicleMovement(\pocketmine\player\Player $rider, \pocketmine\math\Vector3 $pos, float $yaw, float $pitch) : bool

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

php
public function handleRiderInput(\pocketmine\player\Player $rider, \pocketmine\entity\riding\RiderInput $input) : void

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

php
public function handleRiderItemUse(\pocketmine\player\Player $rider, \pocketmine\item\Item $item) : bool

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

php
public function hasMovementUpdate() : bool

initEntity() protected ​

php
protected function initEntity(\pocketmine\nbt\tag\CompoundTag $nbt) : void

isBoosting() ​

php
public function isBoosting() : bool

isDrivenByRiderClient() protected ​

php
protected function isDrivenByRiderClient() : bool

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

php
public function isInContactWithWater() : bool

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

php
public function isInWater() : bool

Returns whether the mob's feet are in water.

isMovedByClient() ​

php
public function isMovedByClient() : bool

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

php
public function isPersistent() : bool

lootingBonus() protected ​

php
protected function lootingBonus(int $perLevel = 1) : int

Vanilla "looting_enchant" loot function: adds 0 to $perLevel extra items per Looting level.

onDeath() protected ​

php
protected function onDeath() : void

onDispose() protected ​

php
protected function onDispose() : void

onFrozenUpdate() ​

php
public function onFrozenUpdate(int $currentTick) : bool

onInteract() ​

php
public function onInteract(\pocketmine\player\Player $player, \pocketmine\math\Vector3 $clickPos) : bool

onInteractWithItem() protected ​

php
protected function onInteractWithItem(\pocketmine\player\Player $player, \pocketmine\item\Item $item) : bool

Called when a player interacts with the mob holding the given item. Returns whether something happened.

playAmbientSound() protected ​

php
protected function playAmbientSound() : void

playMobSound() ​

php
public function playMobSound(string $sound, int $extraData = -1) : void

registerGoals() protected ​

php
abstract protected function registerGoals() : void

Adds the mob's goals to Mob::$goalSelector and Mob::$targetSelector.

resyncClientVehicle() ​

php
public function resyncClientVehicle(\pocketmine\player\Player $rider) : void

Sends the mob's position to the client of its rider, which moved it somewhere it was not allowed to go.

saveNBT() ​

php
public function saveNBT() : \pocketmine\nbt\tag\CompoundTag

scaleDamageForDifficulty() ​

php
public static function scaleDamageForDifficulty(float $damage, int $difficulty) : float

setActorProperty() ​

php
public function setActorProperty(string $name, int|bool|string $value) : void

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

php
public function setAttackTarget(?\pocketmine\entity\Living $target) : void

setNameTag() ​

php
public function setNameTag(string $name) : void

setPersistent() ​

php
public function setPersistent(bool $persistent) : void

setRotation() ​

php
public function setRotation(float $yaw, float $pitch) : void

steer() protected ​

php
protected function steer(\pocketmine\player\Player $rider, \pocketmine\entity\riding\RiderInput $input) : void

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

php
protected function syncNetworkData(\pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection $properties) : void

tickAi() protected ​

php
protected function tickAi(int $currentTick) : void

tryChangeMovement() protected ​

php
protected function tryChangeMovement() : void

tryRide() protected ​

php
protected function tryRide(\pocketmine\player\Player $player) : bool

Makes the player ride this mob after interacting with it, unless sneaking. Returns whether it got on.

updateActivation() protected ​

php
protected function updateActivation() : bool

Returns whether a player is close enough for the mob to run its AI. Called every 20 ticks.

updateMovement() protected ​

php
protected function updateMovement(bool $teleport = false) : void

wasRecentlyHitByPlayer() ​

php
public function wasRecentlyHitByPlayer() : bool

Returns 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).

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