コード例 #1
0
ファイル: McRegion.php プロジェクト: MunkySkunk/BukkitPE
 public static function generate($path, $name, $seed, $generator, array $options = [])
 {
     if (!file_exists($path)) {
         mkdir($path, 0777, true);
     }
     if (!file_exists($path . "/region")) {
         mkdir($path . "/region", 0777);
     }
     //TODO, add extra details
     $levelData = new Compound("Data", ["hardcore" => new Byte("hardcore", 0), "initialized" => new Byte("initialized", 1), "GameType" => new Int("GameType", 0), "generatorVersion" => new Int("generatorVersion", 1), "SpawnX" => new Int("SpawnX", 128), "SpawnY" => new Int("SpawnY", 70), "SpawnZ" => new Int("SpawnZ", 128), "version" => new Int("version", 19133), "DayTime" => new Int("DayTime", 0), "LastPlayed" => new Long("LastPlayed", microtime(true) * 1000), "RandomSeed" => new Long("RandomSeed", $seed), "SizeOnDisk" => new Long("SizeOnDisk", 0), "Time" => new Long("Time", 0), "generatorName" => new String("generatorName", Generator::getGeneratorName($generator)), "generatorOptions" => new String("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""), "LevelName" => new String("LevelName", $name), "GameRules" => new Compound("GameRules", [])]);
     $nbt = new NBT(NBT::BIG_ENDIAN);
     $nbt->setData(new Compound("", ["Data" => $levelData]));
     $buffer = $nbt->writeCompressed();
     file_put_contents($path . "level.dat", $buffer);
 }
コード例 #2
0
 public function __construct(Level $level, $path)
 {
     $this->level = $level;
     $this->path = $path;
     if (!file_exists($this->path)) {
         mkdir($this->path, 0777, true);
     }
     $nbt = new NBT(NBT::BIG_ENDIAN);
     $nbt->readCompressed(file_get_contents($this->getPath() . "level.dat"));
     $levelData = $nbt->getData();
     if ($levelData->Data instanceof Compound) {
         $this->levelData = $levelData->Data;
     } else {
         throw new LevelException("Invalid level.dat");
     }
     if (!isset($this->levelData->generatorName)) {
         $this->levelData->generatorName = new String("generatorName", Generator::getGenerator("DEFAULT"));
     }
     if (!isset($this->levelData->generatorOptions)) {
         $this->levelData->generatorOptions = new String("generatorOptions", "");
     }
 }
コード例 #3
0
ファイル: Level.php プロジェクト: MunkySkunk/BukkitPE
 public function initLevel()
 {
     $generator = $this->generator;
     $this->generatorInstance = new $generator($this->provider->getGeneratorOptions());
     $this->generatorInstance->init($this, new Random($this->getSeed()));
     $this->registerGenerator();
 }
コード例 #4
0
ファイル: Nether.php プロジェクト: gitter-badger/BukkitPE
 public function generateChunk($chunkX, $chunkZ)
 {
     $this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed());
     $noise = Generator::getFastNoise3D($this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16);
     $chunk = $this->level->getChunk($chunkX, $chunkZ);
     for ($x = 0; $x < 16; ++$x) {
         for ($z = 0; $z < 16; ++$z) {
             $biome = Biome::getBiome(Biome::HELL);
             $chunk->setBiomeId($x, $z, $biome->getId());
             $color = [0, 0, 0];
             $bColor = $biome->getColor();
             $color[0] += ($bColor >> 16) ** 2;
             $color[1] += ($bColor >> 8 & 0xff) ** 2;
             $color[2] += ($bColor & 0xff) ** 2;
             $chunk->setBiomeColor($x, $z, $color[0], $color[1], $color[2]);
             for ($y = 0; $y < 128; ++$y) {
                 if ($y === 0 or $y === 127) {
                     $chunk->setBlockId($x, $y, $z, Block::BEDROCK);
                     continue;
                 }
                 $noiseValue = abs($this->emptyHeight - $y) / $this->emptyHeight * $this->emptyAmplitude - $noise[$x][$z][$y];
                 $noiseValue -= 1 - $this->density;
                 if ($noiseValue > 0) {
                     $chunk->setBlockId($x, $y, $z, Block::NETHERRACK);
                 } elseif ($y <= $this->waterHeight) {
                     $chunk->setBlockId($x, $y, $z, Block::STILL_LAVA);
                 }
             }
         }
     }
     foreach ($this->generationPopulators as $populator) {
         $populator->populate($this->level, $chunkX, $chunkZ, $this->random);
     }
 }
コード例 #5
0
ファイル: Normal.php プロジェクト: MunkySkunk/BukkitPE
 public function generateChunk($chunkX, $chunkZ)
 {
     $this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed());
     $noise = Generator::getFastNoise3D($this->noiseBase, 16, 128, 16, 4, 8, 4, $chunkX * 16, 0, $chunkZ * 16);
     $chunk = $this->level->getChunk($chunkX, $chunkZ);
     $biomeCache = [];
     for ($x = 0; $x < 16; ++$x) {
         for ($z = 0; $z < 16; ++$z) {
             $minSum = 0;
             $maxSum = 0;
             $weightSum = 0;
             $biome = $this->pickBiome($chunkX * 16 + $x, $chunkZ * 16 + $z);
             $chunk->setBiomeId($x, $z, $biome->getId());
             $color = [0, 0, 0];
             for ($sx = -self::$SMOOTH_SIZE; $sx <= self::$SMOOTH_SIZE; ++$sx) {
                 for ($sz = -self::$SMOOTH_SIZE; $sz <= self::$SMOOTH_SIZE; ++$sz) {
                     $weight = self::$GAUSSIAN_KERNEL[$sx + self::$SMOOTH_SIZE][$sz + self::$SMOOTH_SIZE];
                     if ($sx === 0 and $sz === 0) {
                         $adjacent = $biome;
                     } else {
                         $index = Level::chunkHash($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz);
                         if (isset($biomeCache[$index])) {
                             $adjacent = $biomeCache[$index];
                         } else {
                             $biomeCache[$index] = $adjacent = $this->pickBiome($chunkX * 16 + $x + $sx, $chunkZ * 16 + $z + $sz);
                         }
                     }
                     $minSum += ($adjacent->getMinElevation() - 1) * $weight;
                     $maxSum += $adjacent->getMaxElevation() * $weight;
                     $bColor = $adjacent->getColor();
                     $color[0] += ($bColor >> 16) ** 2 * $weight;
                     $color[1] += ($bColor >> 8 & 0xff) ** 2 * $weight;
                     $color[2] += ($bColor & 0xff) ** 2 * $weight;
                     $weightSum += $weight;
                 }
             }
             $minSum /= $weightSum;
             $maxSum /= $weightSum;
             $chunk->setBiomeColor($x, $z, sqrt($color[0] / $weightSum), sqrt($color[1] / $weightSum), sqrt($color[2] / $weightSum));
             $solidLand = false;
             for ($y = 127; $y >= 0; --$y) {
                 if ($y === 0) {
                     $chunk->setBlockId($x, $y, $z, Block::BEDROCK);
                     continue;
                 }
                 // A noiseAdjustment of 1 will guarantee ground, a noiseAdjustment of -1 will guarantee air.
                 //$effHeight = min($y - $smoothHeight - $minSum,
                 $noiseAdjustment = 2 * (($maxSum - $y) / ($maxSum - $minSum)) - 1;
                 // To generate caves, we bring the noiseAdjustment down away from 1.
                 $caveLevel = $minSum - 10;
                 $distAboveCaveLevel = max(0, $y - $caveLevel);
                 // must be positive
                 $noiseAdjustment = min($noiseAdjustment, 0.4 + $distAboveCaveLevel / 10);
                 $noiseValue = $noise[$x][$z][$y] + $noiseAdjustment;
                 if ($noiseValue > 0) {
                     $chunk->setBlockId($x, $y, $z, Block::STONE);
                     $solidLand = true;
                 } elseif ($y <= $this->waterHeight && $solidLand == false) {
                     $chunk->setBlockId($x, $y, $z, Block::STILL_WATER);
                 }
             }
         }
     }
     foreach ($this->generationPopulators as $populator) {
         $populator->populate($this->level, $chunkX, $chunkZ, $this->random);
     }
 }