FlockingGoal 5.47.0
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
public const SEARCH_INTERVAL = 100Ticks between two searches of a mob without a (big enough) school: Java reducedTickDelay(200 + rand) = 100-110.
SEARCH_RADIUS
public const SEARCH_RADIUS = 8.0Range in which a mob looks for a school (Java 8 blocks).
Properties
$canFlockWith
public ?\Closure $canFlockWith$cohesionThreshold
public float $cohesionThreshold$highFlockLimit
public int $highFlockLimit$inWater
public bool $inWater$influenceRadius
public float $influenceRadius$lonerChance
public float $lonerChance$lowFlockLimit
public int $lowFlockLimit$mob
public \pocketmine\entity\Mob $mobMethods
__construct()
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()
public function canContinue() : boolcanStart()
public function canStart() : booldispose()
public function dispose() : voidLeaves 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()
public function follow(\pocketmine\entity\ai\goal\FlockingGoal $leader) : boolMakes the mob follow the given leader (spawned herds, tests). Returns false if they can't school together.
getFlags()
public function getFlags() : intgetLeader()
public function getLeader() : ?\pocketmine\entity\MobReturns the leader of this mob's school, null if the mob leads it or has none.
getMob()
public function getMob() : \pocketmine\entity\MobgetSchoolSize()
public function getSchoolSize() : intReturns the number of mobs in the school this mob leads (itself included): 1 for a follower or a lone mob.
isFollower()
public function isFollower() : boolleaveSchool()
public function leaveSchool() : voidLeaves the school: a follower leaves its leader, a leader lets its followers go (they look for a new school).
of()
public static function of(\pocketmine\entity\Mob $mob) : ?\pocketmine\entity\ai\goal\FlockingGoalReturns the flocking goal of a mob, if it has one.
start()
public function start() : voidstop()
public function stop() : voidtick()
public function tick() : void