コード例 #1
0
ファイル: GroundCover.php プロジェクト: MunkySkunk/BukkitPE
 public function populate(ChunkManager $level, $chunkX, $chunkZ, Random $random)
 {
     $chunk = $level->getChunk($chunkX, $chunkZ);
     for ($x = 0; $x < 16; ++$x) {
         for ($z = 0; $z < 16; ++$z) {
             $biome = Biome::getBiome($chunk->getBiomeId($x, $z));
             $cover = $biome->getGroundCover();
             if (count($cover) > 0) {
                 $diffY = 0;
                 if (!$cover[0]->isSolid()) {
                     $diffY = 1;
                 }
                 $column = $chunk->getBlockIdColumn($x, $z);
                 for ($y = 127; $y > 0; --$y) {
                     if ($column[$y] !== "" and !Block::get(ord($column[$y]))->isTransparent()) {
                         break;
                     }
                 }
                 $startY = min(127, $y + $diffY);
                 $endY = $startY - count($cover);
                 for ($y = $startY; $y > $endY and $y >= 0; --$y) {
                     $b = $cover[$startY - $y];
                     if ($column[$y] === "" and $b->isSolid()) {
                         break;
                     }
                     if ($b->getDamage() === 0) {
                         $chunk->setBlockId($x, $y, $z, $b->getId());
                     } else {
                         $chunk->setBlock($x, $y, $z, $b->getId(), $b->getDamage());
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: Flat.php プロジェクト: gitter-badger/BukkitPE
 protected function parsePreset($preset, $chunkX, $chunkZ)
 {
     $this->preset = $preset;
     $preset = explode(";", $preset);
     $version = (int) $preset[0];
     $blocks = isset($preset[1]) ? $preset[1] : "";
     $biome = isset($preset[2]) ? $preset[2] : 1;
     $options = isset($preset[3]) ? $preset[3] : "";
     preg_match_all('#^(([0-9]*x|)([0-9]{1,3})(|:[0-9]{0,2}))$#m', str_replace(",", "\n", $blocks), $matches);
     $y = 0;
     $this->structure = [];
     $this->chunks = [];
     foreach ($matches[3] as $i => $b) {
         $b = Item::fromString($b . $matches[4][$i]);
         $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 = clone $this->level->getChunk($chunkX, $chunkZ);
     $this->chunk->setGenerated();
     $c = Biome::getBiome($biome)->getColor();
     $R = $c >> 16;
     $G = $c >> 8 & 0xff;
     $B = $c & 0xff;
     for ($Z = 0; $Z < 16; ++$Z) {
         for ($X = 0; $X < 16; ++$X) {
             $this->chunk->setBiomeId($X, $Z, $biome);
             $this->chunk->setBiomeColor($X, $Z, $R, $G, $B);
             for ($y = 0; $y < 128; ++$y) {
                 $this->chunk->setBlock($X, $y, $Z, ...$this->structure[$y]);
             }
         }
     }
     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
 public function onRun()
 {
     Block::init();
     Biome::init();
     $manager = new SimpleChunkManager($this->seed);
     $this->saveToThreadStore("generation.level{$this->levelId}.manager", $manager);
     /** @var Generator $generator */
     $generator = $this->generator;
     $generator = new $generator($this->settings);
     $generator->init($manager, new Random($manager->getSeed()));
     $this->saveToThreadStore("generation.level{$this->levelId}.generator", $generator);
 }
コード例 #4
0
ファイル: BaseFullChunk.php プロジェクト: MunkySkunk/BukkitPE
 protected function checkOldBiomes($data)
 {
     if (strlen($data) !== 256) {
         return;
     }
     for ($x = 0; $x < 16; ++$x) {
         for ($z = 0; $z < 16; ++$z) {
             $biome = Biome::getBiome(ord($data[($z << 4) + $x]));
             $this->setBiomeId($x, $z, $biome->getId());
             $c = $biome->getColor();
             $this->setBiomeColor($x, $z, $c >> 16, $c >> 8 & 0xff, $c & 0xff);
         }
     }
 }
コード例 #5
0
ファイル: Level.php プロジェクト: MunkySkunk/BukkitPE
 /**
  * @param int  $x
  * @param int  $z
  * @param bool $generate
  *
  * @return bool
  */
 public function loadChunk($x, $z, $generate = true)
 {
     if (isset($this->chunks[$index = Level::chunkHash($x, $z)])) {
         return true;
     }
     $this->timings->syncChunkLoadTimer->startTiming();
     $this->cancelUnloadChunkRequest($x, $z);
     $chunk = $this->provider->getChunk($x, $z, $generate);
     if ($chunk === null) {
         if ($generate) {
             throw new \InvalidStateException("Could not create new Chunk");
         }
         return false;
     }
     if ($this->provider->getProviderName() == "mcregion") {
         if ($chunk->getBiomeColor(0, 0) == [0, 0, 0]) {
             for ($x = 0; $x < 16; ++$x) {
                 for ($z = 0; $z < 16; ++$z) {
                     $biome = Biome::getBiome(Biome::PLAINS);
                     $chunk->setBiomeId($x, $z, $biome->getId());
                     $c = $biome->getColor();
                     $chunk->setBiomeColor($x, $z, $c >> 16, $c >> 8 & 0xff, $c & 0xff);
                 }
             }
         }
     }
     $this->chunks[$index] = $chunk;
     $chunk->initChunk();
     if ($chunk->getProvider() !== null) {
         $this->server->getPluginManager()->callEvent(new ChunkLoadEvent($chunk, !$chunk->isGenerated()));
     } else {
         $this->unloadChunk($x, $z, false);
         $this->timings->syncChunkLoadTimer->stopTiming();
         return false;
     }
     if (!$chunk->isLightPopulated() and $chunk->isPopulated() and $this->getServer()->getProperty("chunk-ticking.light-updates", false)) {
         $this->getServer()->getScheduler()->scheduleAsyncTask(new LightPopulationTask($this, $chunk));
     }
     if ($this->isChunkInUse($x, $z)) {
         foreach ($this->getChunkLoaders($x, $z) as $loader) {
             $loader->onChunkLoaded($chunk);
         }
     } else {
         $this->unloadChunkRequest($x, $z);
     }
     $this->timings->syncChunkLoadTimer->stopTiming();
     return true;
 }
コード例 #6
0
 public function addBiome(Biome $biome)
 {
     $this->biomes[$biome->getId()] = $biome;
 }
コード例 #7
0
ファイル: Nether.php プロジェクト: gitter-badger/BukkitPE
 public function populateChunk($chunkX, $chunkZ)
 {
     $this->random->setSeed(0xdeadbeef ^ $chunkX << 8 ^ $chunkZ ^ $this->level->getSeed());
     foreach ($this->populators as $populator) {
         $populator->populate($this->level, $chunkX, $chunkZ, $this->random);
     }
     $chunk = $this->level->getChunk($chunkX, $chunkZ);
     $biome = Biome::getBiome($chunk->getBiomeId(7, 7));
     $biome->populateChunk($this->level, $chunkX, $chunkZ, $this->random);
 }
コード例 #8
0
ファイル: Biome.php プロジェクト: MunkySkunk/BukkitPE
 protected static function register($id, Biome $biome)
 {
     self::$biomes[(int) $id] = $biome;
     $biome->setId((int) $id);
     $biome->grassColor = self::generateBiomeColor($biome->getTemperature(), $biome->getRainfall());
 }