Exemple #1
0
 /**
  * @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;
 }