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", "");
     }
 }
示例#2
0
 /**
  * @param string        $data
  * @param LevelProvider $provider
  *
  * @return Chunk
  */
 public static function fromBinary($data, LevelProvider $provider = null)
 {
     $nbt = new NBT(NBT::BIG_ENDIAN);
     try {
         $nbt->readCompressed($data, ZLIB_ENCODING_DEFLATE);
         $chunk = $nbt->getData();
         if (!isset($chunk->Level) or !$chunk->Level instanceof Compound) {
             return null;
         }
         return new Chunk($provider instanceof LevelProvider ? $provider : Anvil::class, $chunk->Level);
     } catch (\Exception $e) {
         return null;
     }
 }