public function populate(Level $level, $chunkX, $chunkZ, Random $random)
 {
     if ($random->nextRange(0, $this->waterOdd) === 0) {
         $v = new Vector3($random->nextRange($chunkX << 4, ($chunkX << 4) + 16), $random->nextRange(0, 128), $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16));
         $pond = new PondObject($random, new WaterBlock());
         if ($pond->canPlaceObject($level, $v)) {
             $pond->placeObject($level, $v);
         }
     }
 }
 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);
         }
     }
 }
 public function populate(Level $level, $chunkX, $chunkZ, Random $random)
 {
     foreach ($this->oreTypes as $type) {
         $ore = new OreObject($random, $type);
         for ($i = 0; $i < $ore->type->clusterCount; ++$i) {
             $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 16);
             $y = $random->nextRange($ore->type->minHeight, $ore->type->maxHeight);
             $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16);
             if ($ore->canPlaceObject($level, $x, $y, $z)) {
                 $ore->placeObject($level, new Vector3($x, $y, $z));
             }
         }
     }
 }
Beispiel #4
0
 public static function growTree(Level $level, Vector3 $pos, Random $random, $type = 0)
 {
     switch ($type & 0x3) {
         case SaplingBlock::SPRUCE:
             if ($random->nextRange(0, 1) === 1) {
                 $tree = new SpruceTreeObject();
             } else {
                 $tree = new PineTreeObject();
             }
             break;
         case SaplingBlock::BIRCH:
             $tree = new SmallTreeObject();
             $tree->type = SaplingBlock::BIRCH;
             break;
         case SaplingBlock::JUNGLE:
             $tree = new SmallTreeObject();
             $tree->type = SaplingBlock::JUNGLE;
             break;
         default:
         case SaplingBlock::OAK:
             /*if($random->nextRange(0, 9) === 0){
             			$tree = new BigTreeObject();
             		}else{*/
             $tree = new SmallTreeObject();
             //}
             break;
     }
     if ($tree->canPlaceObject($level, $pos, $random)) {
         $tree->placeObject($level, $pos, $random);
     }
 }
 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));
         }
     }
 }
 public function __construct($random = false)
 {
     if (!$random instanceof Random) {
         $random = new Random();
     }
     $this->xCoord = $random->nextFloat() * 256;
     $this->yCoord = $random->nextFloat() * 256;
     $this->zCoord = $random->nextFloat() * 256;
     for ($i = 0; $i < 512; ++$i) {
         $this->permutations[$i] = 0;
     }
     for ($i = 0; $i < 256; ++$i) {
         $this->permutations[$i] = $i;
     }
     for ($i = 0; $i < 256; ++$i) {
         $j = $random->nextRange(0, 256 - $i) + $i;
         $k = $this->permutations[$i];
         $this->permutations[$i] = $this->permutations[$j];
         $this->permutations[$j] = $k;
         $this->permutations[$i + 256] = $this->permutations[$i];
     }
 }
 private function findRandomLeavesSize(Random $random)
 {
     $this->totalHeight += $random->nextRange(-1, 2);
     $this->leavesSizeY = 1 + $random->nextRange(0, 2);
     $this->leavesAbsoluteMaxRadius = 2 + $random->nextRange(0, 1);
 }
 public function populate(Level $level, $chunkX, $chunkZ, Random $random)
 {
     if ($random->nextRange(0, MineshaftPopulator::$ODD) === 0) {
         //$mineshaft = new Mineshaft($random);
     }
 }
 private function findRandomLeavesSize(Random $random)
 {
     $this->totalHeight += $random->nextRange(-1, 2);
     $this->leavesBottomY = (int) ($this->totalHeight - $random->nextRange(1, 2) - 3);
     $this->leavesMaxRadius = 1 + $random->nextRange(0, 1);
 }