Skip to content

RaidGardenGoal 5.47.0 ​

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

Extends Goal

Walks to a crop nearby and eats it (vanilla behavior.raid_garden: rabbits and carrots, foxes and sweet berry bushes or cave vines with berries; Java RabbitRaidCarrotGoal and FoxEatBerriesGoal). Once next to the block the mob waits $initialEatDelay ticks, then $eat changes the block (lowers the crop's age, takes the berries). After eating the next search waits $eatDelay ticks, or $fullDelay ticks once the mob ate $maxToEat blocks (0: no limit). Needs mobGriefing.

The search runs at most once every 10-20 seconds while it finds nothing (Java MoveToBlockGoal), and first skips every subchunk of the searched box whose palette has no wanted block state: where there are no crops it costs a few palette checks. A block hanging above air (cave vines) is eaten from the block below it.

Constants ​

SEARCH_INTERVAL ​

php
public const SEARCH_INTERVAL = 200

Ticks between two searches which found nothing, plus up to as many at random.

Properties ​

$condition ​

php
public ?\Closure $condition

$eat ​

php
public \Closure $eat

$eatDelay ​

php
public int $eatDelay

$fullDelay ​

php
public int $fullDelay

$goalRadius ​

php
public float $goalRadius

$initialEatDelay ​

php
public int $initialEatDelay

$isTargetState ​

php
public \Closure $isTargetState

$maxToEat ​

php
public int $maxToEat

$mob ​

php
public \pocketmine\entity\Mob $mob

$searchHeight ​

php
public int $searchHeight

$searchRange ​

php
public int $searchRange

$speedMultiplier ​

php
public float $speedMultiplier

Methods ​

__construct() ​

php
public function __construct(\pocketmine\entity\Mob $mob, \Closure $isTargetState, \Closure $eat, float $speedMultiplier = 1.0, int $searchRange = 16, int $searchHeight = 1, float $goalRadius = 0.5, int $initialEatDelay = 0, int $eatDelay = 40, int $maxToEat = 6, int $fullDelay = 2000, ?\Closure $condition = null)

canContinue() ​

php
public function canContinue() : bool

canStart() ​

php
public function canStart() : bool

changeBlock() ​

php
public static function changeBlock(\pocketmine\entity\Mob $mob, \pocketmine\block\Block $from, \pocketmine\block\Block $to) : bool

Replaces a block the mob changes (eats), unless a plugin cancels EntityBlockChangeEvent. Returns whether the block was changed.

findNearest() ​

php
public function findNearest(\pocketmine\world\World $world, int $x, int $y, int $z) : ?array

Returns the nearest wanted block within the search range around the mob's feet, with the Y of the mob's feet next to it, or null. The block must be reachable: standing on the ground (a crop, a bush), or hanging with air below it and the ground under that (cave vines at head height).

Like Java MoveToBlockGoal.findNearestBlock, the layers are searched by Y offset (0, +1, -1, +2...) and each layer outwards in square rings, stopping at the first reachable block. Only the subchunks whose palette has a wanted state are read, and a block is checked with a lookup of its state ID in those palettes' wanted states.

getFlags() ​

php
public function getFlags() : int

getTarget() ​

php
public function getTarget() : ?\pocketmine\math\Vector3

Returns the block the mob is going to or eating, null when the goal isn't running.

resetSearchDelay() ​

php
public function resetSearchDelay() : void

Makes the next search happen right away (tests, plugins).

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.