Sensing 5.46.0
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()
public function __construct(\pocketmine\entity\Mob $mob)canSee()
public function canSee(\pocketmine\entity\Entity $entity) : booleyeDistanceSquared()
public static function eyeDistanceSquared(\pocketmine\entity\Entity $a, \pocketmine\math\Vector3 $b) : floatgetNearestPlayer()
public function getNearestPlayer(float $range, ?\Closure $filter = null) : ?\pocketmine\player\PlayerReturns the nearest player within range matching the filter (default: any alive player not in spectator mode).
hasLineOfSight()
public static function hasLineOfSight(\pocketmine\entity\Entity $from, \pocketmine\entity\Entity $to) : boolisPluginNpc()
public static function isPluginNpc(\pocketmine\entity\Living $entity) : boolReturns 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()
public static function isTargetablePlayer(\pocketmine\player\Player $player) : boolReturns whether the player can be targeted by hostile mobs (alive, survival or adventure).
isValidTarget()
public function isValidTarget(?\pocketmine\entity\Living $target, float $range) : boolReturns whether the living entity is still a valid target at most $range blocks away.
looksLikePluginNpc()
public static function looksLikePluginNpc(\pocketmine\entity\Living $entity) : boolReturns 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()
public function reset() : voidForgets cached line of sight results; called at the start of every AI update.
setIgnorePluginNpcs()
public static function setIgnorePluginNpcs(bool $ignore) : voidSets whether mobs leave plugin NPCs alone (mobs.ignore-plugin-npcs in pocketmine.yml).
