pocketmine\level\Level::getCollidingEntities PHP Method

getCollidingEntities() public method

Returns the entities colliding the current one inside the AxisAlignedBB
public getCollidingEntities ( AxisAlignedBB $bb, Entity $entity = null ) : array
$bb pocketmine\math\AxisAlignedBB
$entity pocketmine\entity\Entity
return array
    public function getCollidingEntities(AxisAlignedBB $bb, Entity $entity = null) : array
    {
        $nearby = [];
        if ($entity === null or $entity->canCollide) {
            $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 ($entity == null) {
                            if ($ent->boundingBox->intersectsWith($bb)) {
                                $nearby[] = $ent;
                            }
                        } elseif ($entity instanceof Entity and $ent !== $entity and $entity->canCollideWith($ent)) {
                            if ($ent->boundingBox->intersectsWith($bb)) {
                                $nearby[] = $ent;
                            }
                        }
                    }
                }
            }
        }
        return $nearby;
    }
Level