Skip to content

MobDespawner 5.46.0 ​

final class · pocketmine\world\mobs\MobDespawner · source

Bedrock despawning of naturally spawned mobs ("minecraft:despawn" with despawn_from_distance), checked every MobDespawner::CHECK_INTERVAL ticks by the mob:

  • instantly beyond the instant distance from every player: 128 blocks, 44 with simulation distance 4 (PocketMine chunk tick radius 4 or less), 40 for fish;
  • beyond 32 blocks, a 1 in 800 chance per tick once the mob has been that far for 30 seconds;
  • never while a player rides it. Persistent mobs (named, bred, tamed, tempted, spawned by an egg or a command...) never despawn: see \pocketmine\entity\Mob::canDespawn().

Constants ​

CHECK_INTERVAL ​

php
public const CHECK_INTERVAL = 20

FISH_INSTANT_DISTANCE ​

php
public const FISH_INSTANT_DISTANCE = 40

INSTANT_DISTANCE ​

php
public const INSTANT_DISTANCE = 128

RANDOM_CHANCE_PER_TICK ​

php
public const RANDOM_CHANCE_PER_TICK = 800

Chance per tick of a random despawn (1 in 800).

RANDOM_DELAY ​

php
public const RANDOM_DELAY = 600

Ticks a mob must stay beyond RANDOM_DISTANCE before it may despawn randomly.

RANDOM_DISTANCE ​

php
public const RANDOM_DISTANCE = 32

SMALL_SIMULATION_INSTANT_DISTANCE ​

php
public const SMALL_SIMULATION_INSTANT_DISTANCE = 44

Simulation distance 4: mobs despawn beyond the spawning range.

Methods ​

getInstantDistance() ​

php
public static function getInstantDistance(\pocketmine\world\World $world) : int

Instant despawn distance of the world: mobs.spawning.instant-despawn-distance if set, otherwise 44 when the chunk tick radius is 4 or less (Bedrock simulation distance 4), else 128.

shouldDespawn() ​

php
public static function shouldDespawn(\pocketmine\entity\Living $mob, int &$farTicks, int $interval = self::CHECK_INTERVAL) : bool

Returns whether the (non-persistent) mob should despawn now. $farTicks counts how long it has been beyond the random despawn distance.

shouldDespawnWhileFrozen() ​

php
public static function shouldDespawnWhileFrozen(\pocketmine\entity\Living $mob) : bool

Despawn check of a (non-persistent) mob frozen beyond the simulation distance of every player: only the instant despawn rule of MobDespawner::shouldDespawn() applies (same distances, no random despawn, no randomness used), so that mobs left behind by players do not pile up and fill the population caps.

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