Gets the Chunk object
This method must be implemented by all the level formats.
public getChunk ( integer $X, integer $Z, boolean $create = false ) : pocketmine\level\format\FullChunk | pocketmine\level\format\Chunk | ||
$X | integer | absolute Chunk X value |
$Z | integer | absolute Chunk Z value |
$create | boolean | Whether to generate the chunk if it does not exist |
return | pocketmine\level\format\FullChunk | pocketmine\level\format\Chunk |
/** * @param int $x * @param int $z * @param bool $generate * * @return bool */ public function loadChunk($x, $z, $generate = true) { if (isset($this->chunks[$index = PHP_INT_SIZE === 8 ? ($x & 4294967295.0) << 32 | $z & 4294967295.0 : $x . ":" . $z])) { return true; } $this->cancelUnloadChunkRequest($x, $z); $chunk = $this->provider->getChunk($x, $z, $generate); if ($chunk !== null) { $this->chunks[$index] = $chunk; $chunk->initChunk(); } else { $this->timings->syncChunkLoadTimer->startTiming(); $this->provider->loadChunk($x, $z, $generate); $this->timings->syncChunkLoadTimer->stopTiming(); if (($chunk = $this->provider->getChunk($x, $z)) !== null) { $this->chunks[$index] = $chunk; $chunk->initChunk(); } else { return false; } } $this->server->getPluginManager()->callEvent(new ChunkLoadEvent($chunk, !$chunk->isGenerated())); return true; }
/** * @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->cancelUnloadChunkRequest($x, $z); $chunk = $this->provider->getChunk($x, $z, $generate); if ($chunk instanceof FullChunk) { $this->chunks[$index] = $chunk; } else { $this->timings->syncChunkLoadTimer->startTiming(); $this->provider->loadChunk($x, $z, $generate); $this->timings->syncChunkLoadTimer->stopTiming(); if (($chunk = $this->provider->getChunk($x, $z)) instanceof FullChunk) { $this->chunks[$index] = $chunk; } else { return false; } } $this->server->getPluginManager()->callEvent(new ChunkLoadEvent($chunk, !$chunk->isGenerated())); return true; }
/** * @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; } $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; }
/** * @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; }