Skip to content

Sensing 5.46.0 ​

final class · pocketmine\entity\ai\sensing\Sensing · source

Line of sight and target lookups for a mob. Line of sight results are cached until the next AI update, so several goals asking about the same entity cost one ray trace.

Methods ​

__construct() ​

php
public function __construct(\pocketmine\entity\Mob $mob)

canSee() ​

php
public function canSee(\pocketmine\entity\Entity $entity) : bool

eyeDistanceSquared() ​

php
public static function eyeDistanceSquared(\pocketmine\entity\Entity $a, \pocketmine\math\Vector3 $b) : float

getNearestPlayer() ​

php
public function getNearestPlayer(float $range, ?\Closure $filter = null) : ?\pocketmine\player\Player

Returns the nearest player within range matching the filter (default: any alive player not in spectator mode).

hasLineOfSight() ​

php
public static function hasLineOfSight(\pocketmine\entity\Entity $from, \pocketmine\entity\Entity $to) : bool

isPluginNpc() ​

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

Returns whether mobs must leave the entity alone because it is a plugin's NPC (Sensing::looksLikePluginNpc()), unless mobs.ignore-plugin-npcs is off. E.g. a shop NPC that extends Villager is not chased by zombies. Plugins can decide for each target with EntityTargetEvent.

isTargetablePlayer() ​

php
public static function isTargetablePlayer(\pocketmine\player\Player $player) : bool

Returns whether the player can be targeted by hostile mobs (alive, survival or adventure).

isValidTarget() ​

php
public function isValidTarget(?\pocketmine\entity\Living $target, float $range) : bool

Returns whether the living entity is still a valid target at most $range blocks away.

looksLikePluginNpc() ​

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

Returns whether the entity looks like a plugin's NPC (shopkeepers, menus, lobby mobs...): a living entity of a plugin class that has any name, or that stands still for clients (setNoClientPredictions(), e.g. Slapper), or that is not saved with the world (setCanSaveWithChunk(false), e.g. Shopkeepers). Mobs of mob plugins (e.g. Mobs) have none of these.

reset() ​

php
public function reset() : void

Forgets cached line of sight results; called at the start of every AI update.

setIgnorePluginNpcs() ​

php
public static function setIgnorePluginNpcs(bool $ignore) : void

Sets whether mobs leave plugin NPCs alone (mobs.ignore-plugin-npcs in pocketmine.yml).

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