pocketmine\level\generator\populator\CaveNode::place PHP Метод

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

public place ( )
    public function place()
    {
        for ($x = $this->start->getFloorX(); $x < $this->end->getFloorX(); $x++) {
            $xOffset = ($this->chunk->getX() + $x + 0.5 - $this->target->getX()) / $this->horizontalSize;
            for ($z = $this->start->getFloorZ(); $z < $this->end->getFloorZ(); $z++) {
                $zOffset = ($this->chunk->getZ() + $z + 0.5 - $this->target->getZ()) / $this->horizontalSize;
                if ($xOffset * $xOffset + $zOffset * $zOffset >= 1) {
                    continue;
                }
                for ($y = $this->end->getFloorY() - 1; $y >= $this->start->getFloorY(); $y--) {
                    $yOffset = ($y + 0.5 - $this->target->getY()) / $this->verticalSize;
                    if ($yOffset > -0.7 and $xOffset * $xOffset + $yOffset * $yOffset + $zOffset * $zOffset < 1) {
                        $xx = $this->chunk->getX() + $x;
                        $zz = $this->chunk->getZ() + $z;
                        $blockId = $this->level->getBlockIdAt($xx, $y, $zz);
                        if ($blockId == Block::STONE or $blockId == Block::DIRT or $blockId == Block::GRASS) {
                            if ($y < 10) {
                                $this->level->setBlockIdAt($xx, $y, $zz, Block::STILL_LAVA);
                            } else {
                                if ($blockId == Block::GRASS and $this->level->getBlockIdAt($xx, $y - 1, $zz) == Block::DIRT) {
                                    $this->level->setBlockIdAt($xx, $y - 1, $zz, Block::GRASS);
                                }
                                $this->level->setBlockIdAt($xx, $y, $zz, Block::AIR);
                            }
                        }
                    }
                }
            }
        }
    }

Usage Example

Пример #1
0
 private function generateCaveBranch(ChunkManager $level, Vector3 $chunk, Vector3 $target, $horizontalScale, $verticalScale, $horizontalAngle, $verticalAngle, int $startingNode, int $nodeAmount, Random $random)
 {
     $middle = new Vector3($chunk->getX() + 8, 0, $chunk->getZ() + 8);
     $horizontalOffset = 0;
     $verticalOffset = 0;
     if ($nodeAmount <= 0) {
         $size = 7 * 16;
         $nodeAmount = $size - $random->nextBoundedInt($size / 4);
     }
     $intersectionMode = $random->nextBoundedInt($nodeAmount / 2) + $nodeAmount / 4;
     $extraVerticalScale = $random->nextBoundedInt(6) == 0;
     if ($startingNode == -1) {
         $startingNode = $nodeAmount / 2;
         $lastNode = true;
     } else {
         $lastNode = false;
     }
     for (; $startingNode < $nodeAmount; $startingNode++) {
         $horizontalSize = 1.5 + sin($startingNode * pi() / $nodeAmount) * $horizontalScale;
         $verticalSize = $horizontalSize * $verticalScale;
         $target = $target->add(VectorMath::getDirection3D($horizontalAngle, $verticalAngle));
         if ($extraVerticalScale) {
             $verticalAngle *= 0.92;
         } else {
             $verticalScale *= 0.7;
         }
         $verticalAngle += $verticalOffset * 0.1;
         $horizontalAngle += $horizontalOffset * 0.1;
         $verticalOffset *= 0.9;
         $horizontalOffset *= 0.75;
         $verticalOffset += ($random->nextFloat() - $random->nextFloat()) * $random->nextFloat() * 2;
         $horizontalOffset += ($random->nextFloat() - $random->nextFloat()) * $random->nextFloat() * 4;
         if (!$lastNode) {
             if ($startingNode == $intersectionMode and $horizontalScale > 1 and $nodeAmount > 0) {
                 $this->generateCaveBranch($level, $chunk, $target, $random->nextFloat() * 0.5 + 0.5, 1, $horizontalAngle - pi() / 2, $verticalAngle / 3, $startingNode, $nodeAmount, new Random($random->nextInt()));
                 $this->generateCaveBranch($level, $chunk, $target, $random->nextFloat() * 0.5 + 0.5, 1, $horizontalAngle - pi() / 2, $verticalAngle / 3, $startingNode, $nodeAmount, new Random($random->nextInt()));
                 return;
             }
             if ($random->nextBoundedInt(4) == 0) {
                 continue;
             }
         }
         $xOffset = $target->getX() - $middle->getX();
         $zOffset = $target->getZ() - $middle->getZ();
         $nodesLeft = $nodeAmount - $startingNode;
         $offsetHorizontalScale = $horizontalScale + 18;
         if ($xOffset * $xOffset + $zOffset * $zOffset - $nodesLeft * $nodesLeft > $offsetHorizontalScale * $offsetHorizontalScale) {
             return;
         }
         if ($target->getX() < $middle->getX() - 16 - $horizontalSize * 2 or $target->getZ() < $middle->getZ() - 16 - $horizontalSize * 2 or $target->getX() > $middle->getX() + 16 + $horizontalSize * 2 or $target->getZ() > $middle->getZ() + 16 + $horizontalSize * 2) {
             continue;
         }
         $start = new Vector3(floor($target->getX() - $horizontalSize) - $chunk->getX() - 1, floor($target->getY() - $verticalSize) - 1, floor($target->getZ() - $horizontalSize) - $chunk->getZ() - 1);
         $end = new Vector3(floor($target->getX() + $horizontalSize) - $chunk->getX() + 1, floor($target->getY() + $verticalSize) + 1, floor($target->getZ() + $horizontalSize) - $chunk->getZ() + 1);
         $node = new CaveNode($level, $chunk, $start, $end, $target, $verticalSize, $horizontalSize);
         if ($node->canPlace()) {
             $node->place();
         }
         if ($lastNode) {
             break;
         }
     }
 }