Skip to content

GoHomeGoal 5.47.0 ​

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

Extends Goal

Goes back to the mob's home position (see \pocketmine\entity\HomeTrait) from time to time (vanilla behavior.go_home): with a 1 in $interval chance per tick while farther than $goalRadius blocks from it, the mob walks (swims, flies) there; once within $goalRadius $onHome runs (Bedrock on_home). A mob that is already home when the goal gets its chance runs $onHome straight away.

A home farther than GoHomeGoal::LEG_LENGTH blocks is reached in legs of that length towards it (a turtle swims back to the beach it hatched on from hundreds of blocks away): each leg is one bounded path search. When a leg ends without getting the mob at least a block closer (no way there), the goal fails: $onFailed runs (Bedrock on_failed) and the goal waits for its next chance.

Constants ​

LEG_LENGTH ​

php
public const LEG_LENGTH = 24.0

Blocks of each leg towards a distant home.

Properties ​

$condition ​

php
public ?\Closure $condition

$goalRadius ​

php
public float $goalRadius

$interval ​

php
public int $interval

$mob ​

php
public \pocketmine\entity\Mob $mob

$onFailed ​

php
public ?\Closure $onFailed

$onHome ​

php
public ?\Closure $onHome

$speedMultiplier ​

php
public float $speedMultiplier

Methods ​

__construct() ​

php
public function __construct(\pocketmine\entity\Mob $mob, float $speedMultiplier = 1.0, int $interval = 120, float $goalRadius = 0.5, ?\Closure $onHome = null, ?\Closure $onFailed = null, ?\Closure $condition = null)

canContinue() ​

php
public function canContinue() : bool

canStart() ​

php
public function canStart() : bool

getFlags() ​

php
public function getFlags() : int

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.