pocketmine\level\Level::loadChunk PHP Method

loadChunk() public method

public loadChunk ( integer $x, integer $z, boolean $generate = true ) : boolean
$x integer
$z integer
$generate boolean
return boolean
    public function loadChunk(int $x, int $z, bool $generate = true) : bool
    {
        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;
    }

Usage Example

Ejemplo n.º 1
0
 public function createVillager($x, $y, $z, Level $level)
 {
     $x += 0.5;
     $z += 0.5;
     $nbt = new CompoundTag();
     $nbt->Pos = new ListTag("Pos", [new DoubleTag("", $x), new DoubleTag("", $y), new DoubleTag("", $z)]);
     $nbt->Rotation = new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)]);
     $nbt->Health = new ShortTag("Health", 20);
     $nbt->CustomName = new StringTag("CustomName", TextFormat::GOLD . "SHOP");
     $nbt->CustomNameVisible = new ByteTag("CustomNameVisible", 1);
     $level->loadChunk($x >> 4, $z >> 4);
     $villager = Entity::createEntity("Villager", $level->getChunk($x >> 4, $y >> 4), $nbt);
     $villager->spawnToAll();
 }
Level