コード例 #1
0
 public function generateChunk($chunkX, $chunkZ)
 {
     $this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed());
     $hills = [];
     $base = [];
     $incline = [];
     for ($z = 0; $z < 16; ++$z) {
         for ($x = 0; $x < 16; ++$x) {
             $i = ($z << 4) + $x;
             $hills[$i] = $this->noiseHills->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true);
             $base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true);
             if ($base[$i] < 0) {
                 $base[$i] *= 0.5;
             }
         }
     }
     $chunk = $this->level->getChunk($chunkX, $chunkZ);
     for ($z = 0; $z < 16; ++$z) {
         for ($x = 0; $x < 16; ++$x) {
             $i = ($z << 4) + $x;
             $height = $this->worldHeight + $hills[$i] * 14 + $base[$i] * 7;
             $height = (int) $height;
             for ($y = 0; $y < 128; ++$y) {
                 $block = $this->pickBlock($x, $y, $z, $height);
                 $chunk->setBlock($x, $y, $z, ...$block);
             }
         }
     }
 }
コード例 #2
0
ファイル: Flat.php プロジェクト: boybook/PocketMine-MP
 protected function parsePreset($preset)
 {
     $this->preset = $preset;
     $preset = explode(";", $preset);
     $version = (int) $preset[0];
     $blocks = @$preset[1];
     $biome = isset($preset[2]) ? $preset[2] : 1;
     $options = isset($preset[3]) ? $preset[3] : "";
     preg_match_all('#(([0-9]{0,})x?([0-9]{1,3}:?[0-9]{0,2})),?#', $blocks, $matches);
     $y = 0;
     $this->structure = [];
     $this->chunks = [];
     foreach ($matches[3] as $i => $b) {
         $b = Item::fromString($b);
         $cnt = $matches[2][$i] === "" ? 1 : intval($matches[2][$i]);
         for ($cY = $y, $y += $cnt; $cY < $y; ++$cY) {
             $this->structure[$cY] = [$b->getID(), $b->getDamage()];
         }
     }
     $this->floorLevel = $y;
     for (; $y < 0xff; ++$y) {
         $this->structure[$y] = [0, 0];
     }
     $this->chunk = $this->level->getChunk(0, 0);
     $this->chunk->setGenerated();
     for ($Z = 0; $Z < 16; ++$Z) {
         for ($X = 0; $X < 16; ++$X) {
             for ($y = 0; $y < 128; ++$y) {
                 if ($this->structure[$y][0] !== 0) {
                     $this->chunk->setBlockId($X, $y, $Z, $this->structure[$y][0]);
                 }
                 if ($this->structure[$y][0] !== 0) {
                     $this->chunk->setBlockData($X, $y, $Z, $this->structure[$y][1]);
                 }
             }
         }
     }
     preg_match_all('#(([0-9a-z_]{1,})\\(?([0-9a-z_ =:]{0,})\\)?),?#', $options, $matches);
     foreach ($matches[2] as $i => $option) {
         $params = true;
         if ($matches[3][$i] !== "") {
             $params = [];
             $p = explode(" ", $matches[3][$i]);
             foreach ($p as $k) {
                 $k = explode("=", $k);
                 if (isset($k[1])) {
                     $params[$k[0]] = $k[1];
                 }
             }
         }
         $this->options[$option] = $params;
     }
 }
コード例 #3
0
ファイル: Normal.php プロジェクト: hlogeon/PocketMineJs-MP
 public function generateChunk($chunkX, $chunkZ)
 {
     $this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed());
     $hills = [];
     $base = [];
     for ($z = 0; $z < 16; ++$z) {
         for ($x = 0; $x < 16; ++$x) {
             $i = ($z << 4) + $x;
             $hills[$i] = $this->noiseHills->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true);
             $base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true);
             if ($base[$i] < 0) {
                 $base[$i] *= 0.5;
             }
         }
     }
     $chunk = $this->level->getChunk($chunkX, $chunkZ);
     for ($z = 0; $z < 16; ++$z) {
         for ($x = 0; $x < 16; ++$x) {
             $i = ($z << 4) + $x;
             $height = $this->worldHeight + $hills[$i] * 14 + $base[$i] * 7;
             $height = (int) $height;
             for ($y = 0; $y < 128; ++$y) {
                 $diff = $height - $y;
                 if ($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)) {
                     $chunk->setBlockId($x, $y, $z, Block::BEDROCK);
                 } elseif ($diff > 2) {
                     $chunk->setBlockId($x, $y, $z, Block::STONE);
                 } elseif ($diff > 0) {
                     $chunk->setBlockId($x, $y, $z, Block::DIRT);
                 } elseif ($y <= $this->waterHeight) {
                     if ($this->waterHeight - $y <= 1 and $diff === 0) {
                         $chunk->setBlockId($x, $y, $z, Block::SAND);
                     } elseif ($diff === 0) {
                         $chunk->setBlockId($x, $y, $z, Block::DIRT);
                     } else {
                         $chunk->setBlockId($x, $y, $z, Block::STILL_WATER);
                     }
                 } elseif ($diff === 0) {
                     $chunk->setBlockId($x, $y, $z, Block::GRASS);
                 }
             }
         }
     }
 }
コード例 #4
0
ファイル: Normal.php プロジェクト: rryy/PocketMine-MP
 public function generateChunk($chunkX, $chunkZ)
 {
     $this->random->setSeed(0.0 ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed());
     $hills = [];
     $patches = [];
     $patchesSmall = [];
     $base = [];
     for ($z = 0; $z < 16; ++$z) {
         for ($x = 0; $x < 16; ++$x) {
             $i = ($z << 4) + $x;
             $hills[$i] = $this->noiseHills->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true);
             $patches[$i] = $this->noisePatches->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true);
             $patchesSmall[$i] = $this->noisePatchesSmall->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true);
             $base[$i] = $this->noiseBase->noise2D($x + ($chunkX << 4), $z + ($chunkZ << 4), true);
             if ($base[$i] < 0) {
                 $base[$i] *= 0.5;
             }
         }
     }
     $chunk = $this->level->getChunk($chunkX, $chunkZ);
     for ($chunkY = 0; $chunkY < 8; ++$chunkY) {
         $startY = $chunkY << 4;
         $endY = $startY + 16;
         for ($z = 0; $z < 16; ++$z) {
             for ($x = 0; $x < 16; ++$x) {
                 $i = ($z << 4) + $x;
                 $height = $this->worldHeight + $hills[$i] * 14 + $base[$i] * 7;
                 $height = (int) $height;
                 for ($y = $startY; $y < $endY; ++$y) {
                     $diff = $height - $y;
                     if ($y <= 4 and ($y === 0 or $this->random->nextFloat() < 0.75)) {
                         $chunk->setBlockId($x, $y, $z, Block::BEDROCK);
                     } elseif ($diff > 2) {
                         $chunk->setBlockId($x, $y, $z, Block::STONE);
                     } elseif ($diff > 0) {
                         if ($patches[$i] > 0.7) {
                             $chunk->setBlockId($x, $y, $z, Block::STONE);
                         } elseif ($patches[$i] < -0.8) {
                             $chunk->setBlockId($x, $y, $z, Block::GRAVEL);
                         } else {
                             $chunk->setBlockId($x, $y, $z, Block::DIRT);
                         }
                     } elseif ($y <= $this->waterHeight) {
                         if ($this->waterHeight - $y <= 1 and $diff === 0) {
                             $chunk->setBlockId($x, $y, $z, Block::SAND);
                         } elseif ($diff === 0) {
                             if ($patchesSmall[$i] > 0.3) {
                                 $chunk->setBlockId($x, $y, $z, Block::GRAVEL);
                             } elseif ($patchesSmall[$i] < -0.45) {
                                 $chunk->setBlockId($x, $y, $z, Block::SAND);
                             } else {
                                 $chunk->setBlockId($x, $y, $z, Block::DIRT);
                             }
                         } else {
                             $chunk->setBlockId($x, $y, $z, Block::STILL_WATER);
                         }
                     } elseif ($diff === 0) {
                         if ($patches[$i] > 0.7) {
                             $chunk->setBlockId($x, $y, $z, Block::STONE);
                         } elseif ($patches[$i] < -0.8) {
                             $chunk->setBlockId($x, $y, $z, Block::GRAVEL);
                         } else {
                             $chunk->setBlockId($x, $y, $z, Block::GRASS);
                         }
                     }
                 }
             }
         }
     }
 }