示例#1
0
 public static function generate($path, $name, $seed, $generator, array $options = [])
 {
     if (!file_exists($path)) {
         mkdir($path, 0777, true);
     }
     if (!file_exists($path . "/region")) {
         mkdir($path . "/region", 0777);
     }
     //TODO, add extra details
     $levelData = new Compound("Data", ["hardcore" => new Byte("hardcore", 0), "initialized" => new Byte("initialized", 1), "GameType" => new Int("GameType", 0), "generatorVersion" => new Int("generatorVersion", 1), "SpawnX" => new Int("SpawnX", 128), "SpawnY" => new Int("SpawnY", 70), "SpawnZ" => new Int("SpawnZ", 128), "version" => new Int("version", 19133), "DayTime" => new Int("DayTime", 0), "LastPlayed" => new Long("LastPlayed", microtime(true) * 1000), "RandomSeed" => new Long("RandomSeed", $seed), "SizeOnDisk" => new Long("SizeOnDisk", 0), "Time" => new Long("Time", 0), "generatorName" => new String("generatorName", Generator::getGeneratorName($generator)), "generatorOptions" => new String("generatorOptions", isset($options["preset"]) ? $options["preset"] : ""), "LevelName" => new String("LevelName", $name), "GameRules" => new Compound("GameRules", [])]);
     $nbt = new NBT(NBT::BIG_ENDIAN);
     $nbt->setData(new Compound("", ["Data" => $levelData]));
     $buffer = $nbt->writeCompressed();
     file_put_contents($path . "level.dat", $buffer);
 }
 public function saveLevelData()
 {
     $nbt = new NBT(NBT::BIG_ENDIAN);
     $nbt->setData(new Compound("", ["Data" => $this->levelData]));
     $buffer = $nbt->writeCompressed();
     file_put_contents($this->getPath() . "level.dat", $buffer);
 }
示例#3
0
 public function toBinary()
 {
     $nbt = clone $this->getNBT();
     $nbt->xPos = new Int("xPos", $this->x);
     $nbt->zPos = new Int("zPos", $this->z);
     $nbt->Sections = new Enum("Sections", []);
     $nbt->Sections->setTagType(NBT::TAG_Compound);
     foreach ($this->getSections() as $section) {
         if ($section instanceof EmptyChunkSection) {
             continue;
         }
         $nbt->Sections[$section->getY()] = new Compound(null, ["Y" => new Byte("Y", $section->getY()), "Blocks" => new ByteArray("Blocks", $section->getIdArray()), "Data" => new ByteArray("Data", $section->getDataArray()), "BlockLight" => new ByteArray("BlockLight", $section->getLightArray()), "SkyLight" => new ByteArray("SkyLight", $section->getSkyLightArray())]);
     }
     $nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray());
     $nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray());
     $entities = [];
     foreach ($this->getEntities() as $entity) {
         if (!$entity instanceof Player and !$entity->closed) {
             $entity->saveNBT();
             $entities[] = $entity->namedtag;
         }
     }
     $nbt->Entities = new Enum("Entities", $entities);
     $nbt->Entities->setTagType(NBT::TAG_Compound);
     $tiles = [];
     foreach ($this->getTiles() as $tile) {
         $tile->saveNBT();
         $tiles[] = $tile->namedtag;
     }
     $nbt->TileEntities = new Enum("TileEntities", $tiles);
     $nbt->TileEntities->setTagType(NBT::TAG_Compound);
     $extraData = new BinaryStream();
     $extraData->putInt(count($this->getBlockExtraDataArray()));
     foreach ($this->getBlockExtraDataArray() as $key => $value) {
         $extraData->putInt($key);
         $extraData->putShort($value);
     }
     $nbt->ExtraData = new ByteArray("ExtraData", $extraData->getBuffer());
     $writer = new NBT(NBT::BIG_ENDIAN);
     $nbt->setName("Level");
     $writer->setData(new Compound("", ["Level" => $nbt]));
     return $writer->writeCompressed(ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
 }