pocketmine\level\Level::getNearbyEntities PHP Method

getNearbyEntities() public method

Returns the entities near the current one inside the AxisAlignedBB
public getNearbyEntities ( AxisAlignedBB $bb, Entity $entity = null ) : array
$bb pocketmine\math\AxisAlignedBB
$entity pocketmine\entity\Entity
return array
    public function getNearbyEntities(AxisAlignedBB $bb, Entity $entity = null) : array
    {
        $nearby = [];
        $minX = Math::floorFloat(($bb->minX - 2) / 16);
        $maxX = Math::ceilFloat(($bb->maxX + 2) / 16);
        $minZ = Math::floorFloat(($bb->minZ - 2) / 16);
        $maxZ = Math::ceilFloat(($bb->maxZ + 2) / 16);
        for ($x = $minX; $x <= $maxX; ++$x) {
            for ($z = $minZ; $z <= $maxZ; ++$z) {
                foreach ($this->getChunkEntities($x, $z) as $ent) {
                    if ($ent instanceof Player and $ent->isSpectator()) {
                        continue;
                    }
                    if ($ent !== $entity and $ent->boundingBox->intersectsWith($bb)) {
                        $nearby[] = $ent;
                    }
                }
            }
        }
        return $nearby;
    }
Level