Skip to content

FlockingGoal 5.47.0 ​

class · pocketmine\entity\ai\goal\FlockingGoal · source

Extends Goal

Schools of fish and pods of dolphins (Bedrock minecraft:flocking), as leaders and followers like Java AbstractSchoolingFish / FollowFlockLeaderGoal: a mob without a school looks for one every 5 seconds or so (staggered, one entity query per search), joins the biggest school nearby that still has room (high_flock_limit members), otherwise leads the mobs without a school around it. A school smaller than low_flock_limit keeps looking and merges into a bigger one. With loner_chance the mob skips a search and stays alone for a while.

The leader wanders with its usual goals; each follower swims to its own place around it, cohesion_threshold blocks from the leader in a direction of its own (spread by the golden angle, a little above or below), so that the members keep apart from each other (the separation) instead of piling up on the leader and pushing each other all the time; it catches up faster beyond influence_radius. A follower leaves the school when the leader dies, is more than 11 blocks away (Java) or, with in_water, when it is out of the water. Bedrock steers every member with weighted cohesion/separation/goal forces; the leader model gives the same look (tight schools that wander together) at the cost of one neighbour query per few seconds per lone mob and one path update per follower every 10 ticks.

Constants ​

SEARCH_INTERVAL ​

php
public const SEARCH_INTERVAL = 100

Ticks between two searches of a mob without a (big enough) school: Java reducedTickDelay(200 + rand) = 100-110.

SEARCH_RADIUS ​

php
public const SEARCH_RADIUS = 8.0

Range in which a mob looks for a school (Java 8 blocks).

Properties ​

$canFlockWith ​

php
public ?\Closure $canFlockWith

$cohesionThreshold ​

php
public float $cohesionThreshold

$highFlockLimit ​

php
public int $highFlockLimit

$inWater ​

php
public bool $inWater

$influenceRadius ​

php
public float $influenceRadius

$lonerChance ​

php
public float $lonerChance

$lowFlockLimit ​

php
public int $lowFlockLimit

$mob ​

php
public \pocketmine\entity\Mob $mob

Methods ​

__construct() ​

php
public function __construct(\pocketmine\entity\Mob $mob, float $influenceRadius = 3.0, int $lowFlockLimit = 4, int $highFlockLimit = 8, float $lonerChance = 0.1, float $cohesionThreshold = 1.95, bool $inWater = true, ?\Closure $canFlockWith = null)

canContinue() ​

php
public function canContinue() : bool

canStart() ​

php
public function canStart() : bool

dispose() ​

php
public function dispose() : void

Leaves the school and forgets the mob (when it is closed): the goal refers to its mob, so the entry would only be freed with the WeakMap by PHP 8.4 and later.

follow() ​

php
public function follow(\pocketmine\entity\ai\goal\FlockingGoal $leader) : bool

Makes the mob follow the given leader (spawned herds, tests). Returns false if they can't school together.

getFlags() ​

php
public function getFlags() : int

getLeader() ​

php
public function getLeader() : ?\pocketmine\entity\Mob

Returns the leader of this mob's school, null if the mob leads it or has none.

getMob() ​

php
public function getMob() : \pocketmine\entity\Mob

getSchoolSize() ​

php
public function getSchoolSize() : int

Returns the number of mobs in the school this mob leads (itself included): 1 for a follower or a lone mob.

isFollower() ​

php
public function isFollower() : bool

leaveSchool() ​

php
public function leaveSchool() : void

Leaves the school: a follower leaves its leader, a leader lets its followers go (they look for a new school).

of() ​

php
public static function of(\pocketmine\entity\Mob $mob) : ?\pocketmine\entity\ai\goal\FlockingGoal

Returns the flocking goal of a mob, if it has one.

start() ​

php
public function start() : void

stop() ​

php
public function stop() : void

tick() ​

php
public function tick() : void

VanillaMine is a fork of PocketMine-MP. Not affiliated with the PMMP team or Mojang.