pocketmine\level\generator\object\Tree::canPlaceObject PHP Метод

canPlaceObject() публичный Метод

public canPlaceObject ( pocketmine\level\ChunkManager $level, $x, $y, $z, Random $random )
$level pocketmine\level\ChunkManager
$random pocketmine\utils\Random
    public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random)
    {
        $radiusToCheck = 0;
        for ($yy = 0; $yy < $this->treeHeight + 3; ++$yy) {
            if ($yy == 1 or $yy === $this->treeHeight) {
                ++$radiusToCheck;
            }
            for ($xx = -$radiusToCheck; $xx < $radiusToCheck + 1; ++$xx) {
                for ($zz = -$radiusToCheck; $zz < $radiusToCheck + 1; ++$zz) {
                    if (!isset($this->overridable[$level->getBlockIdAt($x + $xx, $y + $yy, $z + $zz)])) {
                        return false;
                    }
                }
            }
        }
        return true;
    }

Usage Example

Пример #1
0
 public function canPlaceObject(ChunkManager $level, $x, $y, $z, Random $random)
 {
     if (!parent::canPlaceObject($level, $x, $y, $z, $random) or $level->getBlockIdAt($x, $y, $z) == Block::WATER or $level->getBlockIdAt($x, $y, $z) == Block::STILL_WATER) {
         return false;
     }
     $base = new Vector3($x, $y, $z);
     $this->totalHeight = $this->baseHeight + $random->nextBoundedInt(12);
     $availableSpace = $this->getAvailableBlockSpace($level, $base, $base->add(0, $this->totalHeight - 1, 0));
     if ($availableSpace > $this->baseHeight or $availableSpace == -1) {
         if ($availableSpace != -1) {
             $this->totalHeight = $availableSpace;
         }
         return true;
     }
     return false;
 }