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", ""); } }
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::LITTLE_ENDIAN); $nbt->read(substr(file_get_contents($this->getPath() . "level.dat"), 8)); $levelData = $nbt->getData(); if ($levelData instanceof Compound) { $this->levelData = $levelData; } 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", ""); } $this->db = new \LevelDB($this->path . "/db", ["compression" => LEVELDB_ZLIB_COMPRESSION]); }
/** * Init the default level data * * @param Server $server * @param string $name * @param string $path * @param string $provider Class that extends LevelProvider * * @throws \Exception */ public function __construct(Server $server, $name, $path, $provider) { $this->blockStates = Block::$fullList; $this->levelId = static::$levelIdCounter++; $this->blockMetadata = new BlockMetadataStore($this); $this->server = $server; $this->autoSave = $server->getAutoSave(); /** Weather Config Loader **/ $this->rainprob = $this->getServer()->getProperty("weather.rain.possibility", 10); $this->raintime[] = $this->getServer()->getProperty("weather.rain.time.min", 30); $this->raintime[] = $this->getServer()->getProperty("weather.rain.time.max", 120); $this->rainfall[] = $this->getServer()->getProperty("weather.rain.rainfall.min", 1000); $this->rainfall[] = $this->getServer()->getProperty("weather.rain.rainfall.max", 100000); /** @var LevelProvider $provider */ if (is_subclass_of($provider, LevelProvider::class, true)) { $this->provider = new $provider($this, $path); } else { throw new LevelException("Provider is not a subclass of LevelProvider"); } $this->server->getLogger()->info($this->server->getLanguage()->translateString("BukkitPE.level.preparing", [$this->provider->getName()])); $this->generator = Generator::getGenerator($this->provider->getGenerator()); $this->blockOrder = $provider::getProviderOrder(); $this->useSections = $provider::usesChunkSection(); $this->folderName = $name; $this->updateQueue = new ReversePriorityQueue(); $this->updateQueue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH); $this->time = (int) $this->provider->getTime(); foreach ($this->getServer()->getProperty("disable-block-ticking", []) as $id) { $ticked = isset($this->randomTickBlocks[$id]); if ($ticked === true) { unset($this->randomTickBlocks[$id]); } } $this->updateRedstoneQueue = new ReversePriorityQueue(); $this->updateRedstoneQueue->setExtractFlags(\SplPriorityQueue::EXTR_BOTH); $this->chunkTickRadius = min($this->server->getViewDistance(), max(1, (int) $this->server->getProperty("chunk-ticking.tick-radius", 4))); $this->chunksPerTick = (int) $this->server->getProperty("chunk-ticking.per-tick", 40); $this->chunkGenerationQueueSize = (int) $this->server->getProperty("chunk-generation.queue-size", 8); $this->chunkPopulationQueueSize = (int) $this->server->getProperty("chunk-generation.population-queue-size", 2); $this->chunkTickList = []; $this->clearChunksOnTick = (bool) $this->server->getProperty("chunk-ticking.clear-tick-list", true); $this->cacheChunks = (bool) $this->server->getProperty("chunk-sending.cache-chunks", false); $this->timings = new LevelTimings($this); $this->temporalPosition = new Position(0, 0, 0, $this); $this->temporalVector = new Vector3(0, 0, 0); $this->tickRate = 1; }