コード例 #1
0
 public function placeObject(Level $level, Vector3 $pos, Random $random)
 {
     if ($this->leavesSizeY === -1 or $this->leavesAbsoluteMaxRadius === -1) {
         $this->findRandomLeavesSize($random);
     }
     $level->setBlockRaw(new Vector3($pos->x, $pos->y - 1, $pos->z), new DirtBlock());
     $leavesRadius = 0;
     $leavesMaxRadius = 1;
     $leavesBottomY = $this->totalHeight - $this->leavesSizeY;
     $firstMaxedRadius = false;
     for ($leavesY = 0; $leavesY <= $leavesBottomY; ++$leavesY) {
         $yy = $this->totalHeight - $leavesY;
         for ($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) {
             for ($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) {
                 if (abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) {
                     $level->setBlockRaw(new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz), new LeavesBlock($this->type));
                 }
             }
         }
         if ($leavesRadius >= $leavesMaxRadius) {
             $leavesRadius = $firstMaxedRadius ? 1 : 0;
             $firstMaxedRadius = true;
             if (++$leavesMaxRadius > $this->leavesAbsoluteMaxRadius) {
                 $leavesMaxRadius = $this->leavesAbsoluteMaxRadius;
             }
         } else {
             ++$leavesRadius;
         }
     }
     $trunkHeightReducer = $random->nextRange(0, 3);
     for ($yy = 0; $yy < $this->totalHeight - $trunkHeightReducer; ++$yy) {
         $level->setBlockRaw(new Vector3($pos->x, $pos->y + $yy, $pos->z), new WoodBlock($this->type));
     }
 }
コード例 #2
0
 public function placeObject(Level $level, Vector3 $pos, Random $random)
 {
     if ($this->leavesBottomY === -1 or $this->leavesMaxRadius === -1) {
         $this->findRandomLeavesSize();
     }
     $level->setBlockRaw(new Vector3($pos->x, $pos->y - 1, $pos->z), new DirtBlock());
     $leavesRadius = 0;
     for ($yy = $this->totalHeight; $yy >= $this->leavesBottomY; --$yy) {
         for ($xx = -$leavesRadius; $xx <= $leavesRadius; ++$xx) {
             for ($zz = -$leavesRadius; $zz <= $leavesRadius; ++$zz) {
                 if (abs($xx) != $leavesRadius or abs($zz) != $leavesRadius or $leavesRadius <= 0) {
                     $level->setBlockRaw(new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz), new LeavesBlock($this->type));
                 }
             }
         }
         if ($leavesRadius > 0 and $yy === $pos->y + $this->leavesBottomY + 1) {
             --$leavesRadius;
         } elseif ($leavesRadius < $this->leavesMaxRadius) {
             ++$leavesRadius;
         }
     }
     for ($yy = 0; $yy < $this->totalHeight - 1; ++$yy) {
         $level->setBlockRaw(new Vector3($pos->x, $pos->y + $yy, $pos->z), new WoodBlock($this->type));
     }
 }
コード例 #3
0
 public function placeObject(Level $level, Vector3 $pos, Random $random)
 {
     // The base dirt block
     $dirtpos = new Vector3($pos->x, $pos->y - 1, $pos->z);
     $level->setBlockRaw($dirtpos, new DirtBlock());
     // Adjust the tree trunk's height randomly
     //    plot [-14:11] int( x / 8 ) + 5
     //    - min=4 (all leaves are 4 tall, some trunk must show)
     //    - max=6 (top leaves are within ground-level whacking range
     //             on all small trees)
     $heightPre = $random->nextRange(-14, 11);
     $this->trunkHeight = intval($heightPre / 8) + 5;
     // Adjust the starting leaf density using the trunk height as a
     // starting position (tall trees with skimpy leaves don't look
     // too good)
     $leafPre = $random->nextRange($this->trunkHeight, 10) / 20;
     // (TODO: seed may apply)
     // Now build the tree (from the top down)
     $leaflevel = 0;
     for ($yy = $this->trunkHeight + 1; $yy >= 0; --$yy) {
         if ($leaflevel < self::$leavesHeight) {
             // The size is a slight variation on the trunkheight
             $radius = self::$leafRadii[$leaflevel] + $leafPre;
             $bRadius = 3;
             for ($xx = -$bRadius; $xx <= $bRadius; ++$xx) {
                 for ($zz = -$bRadius; $zz <= $bRadius; ++$zz) {
                     if (sqrt($xx * $xx + $zz * $zz) <= $radius) {
                         $leafpos = new Vector3($pos->x + $xx, $pos->y + $yy, $pos->z + $zz);
                         $level->setBlockRaw($leafpos, new LeavesBlock($this->type));
                     }
                 }
             }
             $leaflevel++;
         }
         // Place the trunk last
         if ($leaflevel > 1) {
             $trunkpos = new Vector3($pos->x, $pos->y + $yy, $pos->z);
             $level->setBlockRaw($trunkpos, new WoodBlock($this->type));
         }
     }
 }
コード例 #4
0
 public static function growGrass(Level $level, Vector3 $pos, Random $random, $count = 15, $radius = 10)
 {
     $arr = array(BlockAPI::get(DANDELION, 0), BlockAPI::get(CYAN_FLOWER, 0), BlockAPI::get(TALL_GRASS, 1), BlockAPI::get(TALL_GRASS, 1), BlockAPI::get(TALL_GRASS, 1), BlockAPI::get(TALL_GRASS, 1));
     $arrC = count($arr) - 1;
     for ($c = 0; $c < $count; ++$c) {
         $x = $random->nextRange($pos->x - $radius, $pos->x + $radius);
         $z = $random->nextRange($pos->z - $radius, $pos->z + $radius);
         if ($level->level->getBlockID($x, $pos->y + 1, $z) === AIR and $level->level->getBlockID($x, $pos->y, $z) === GRASS) {
             $t = $arr[$random->nextRange(0, $arrC)];
             $level->setBlockRaw(new Vector3($x, $pos->y + 1, $z), $t);
         }
     }
 }
コード例 #5
0
ファイル: OreObject.php プロジェクト: ungarscool1/Multicraft
 public function placeObject(Level $level, Vector3 $pos)
 {
     $clusterSize = (int) $this->type->clusterSize;
     $angle = $this->random->nextFloat() * M_PI;
     $offset = VectorMath::getDirection2D($angle)->multiply($clusterSize)->divide(8);
     $x1 = $pos->x + 8 + $offset->x;
     $x2 = $pos->x + 8 - $offset->x;
     $z1 = $pos->z + 8 + $offset->y;
     $z2 = $pos->z + 8 - $offset->y;
     $y1 = $pos->y + $this->random->nextRange(0, 3) + 2;
     $y2 = $pos->y + $this->random->nextRange(0, 3) + 2;
     for ($count = 0; $count <= $clusterSize; ++$count) {
         $seedX = $x1 + ($x2 - $x1) * $count / $clusterSize;
         $seedY = $y1 + ($y2 - $y1) * $count / $clusterSize;
         $seedZ = $z1 + ($z2 - $z1) * $count / $clusterSize;
         $size = ((sin($count * (M_PI / $clusterSize)) + 1) * $this->random->nextFloat() * $clusterSize / 16 + 1) / 2;
         $startX = (int) ($seedX - $size);
         $startY = (int) ($seedY - $size);
         $startZ = (int) ($seedZ - $size);
         $endX = (int) ($seedX + $size);
         $endY = (int) ($seedY + $size);
         $endZ = (int) ($seedZ + $size);
         for ($x = $startX; $x <= $endX; ++$x) {
             $sizeX = pow(($x + 0.5 - $seedX) / $size, 2);
             if ($sizeX < 1) {
                 for ($y = $startY; $y <= $endY; ++$y) {
                     $sizeY = pow(($y + 0.5 - $seedY) / $size, 2);
                     if ($y > 0 and $sizeX + $sizeY < 1) {
                         for ($z = $startZ; $z <= $endZ; ++$z) {
                             $sizeZ = pow(($z + 0.5 - $seedZ) / $size, 2);
                             if ($sizeX + $sizeY + $sizeZ < 1 and $level->level->getBlockID($x, $y, $z) === STONE) {
                                 $level->setBlockRaw(new Vector3($x, $y, $z), $this->type->material);
                             }
                         }
                     }
                 }
             }
         }
     }
 }