mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 16:59:44 +00:00
Goodbye McRegion o/
This commit is contained in:
parent
8d83d59cf0
commit
8cb24547ff
@ -26,60 +26,25 @@ namespace pocketmine\level\format\io\region;
|
||||
use pocketmine\level\format\Chunk;
|
||||
use pocketmine\level\format\io\ChunkUtils;
|
||||
use pocketmine\level\format\io\exception\CorruptedChunkException;
|
||||
use pocketmine\level\format\io\WritableLevelProvider;
|
||||
use pocketmine\level\format\SubChunk;
|
||||
use pocketmine\nbt\BigEndianNbtSerializer;
|
||||
use pocketmine\nbt\NBT;
|
||||
use pocketmine\nbt\NbtDataException;
|
||||
use pocketmine\nbt\tag\ByteArrayTag;
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\nbt\tag\IntArrayTag;
|
||||
use pocketmine\nbt\tag\ListTag;
|
||||
use function str_repeat;
|
||||
use function substr;
|
||||
|
||||
class McRegion extends RegionLevelProvider implements WritableLevelProvider{
|
||||
class McRegion extends RegionLevelProvider{
|
||||
|
||||
/**
|
||||
* @param Chunk $chunk
|
||||
*
|
||||
* @return string
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
protected function serializeChunk(Chunk $chunk) : string{
|
||||
$nbt = new CompoundTag("Level", []);
|
||||
$nbt->setInt("xPos", $chunk->getX());
|
||||
$nbt->setInt("zPos", $chunk->getZ());
|
||||
|
||||
$nbt->setLong("LastUpdate", 0); //TODO
|
||||
$nbt->setByte("TerrainPopulated", $chunk->isPopulated() ? 1 : 0);
|
||||
$nbt->setByte("LightPopulated", 0);
|
||||
|
||||
$ids = "";
|
||||
$data = "";
|
||||
$subChunks = $chunk->getSubChunks();
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
for($z = 0; $z < 16; ++$z){
|
||||
for($y = 0; $y < 8; ++$y){
|
||||
$subChunk = $subChunks[$y];
|
||||
$ids .= substr($subChunk->getBlockIdArray(), ($x << 8) | ($z << 4), 16);
|
||||
$data .= substr($subChunk->getBlockDataArray(), ($x << 7) | ($z << 3), 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$nbt->setByteArray("Blocks", $ids);
|
||||
$nbt->setByteArray("Data", $data);
|
||||
$nbt->setByteArray("SkyLight", str_repeat("\x00", 16384));
|
||||
$nbt->setByteArray("BlockLight", str_repeat("\x00", 16384));
|
||||
|
||||
$nbt->setByteArray("Biomes", $chunk->getBiomeIdArray()); //doesn't exist in regular McRegion, this is here for PocketMine-MP only
|
||||
$nbt->setByteArray("HeightMap", str_repeat("\x00", 256)); //this is ByteArray in McRegion, but IntArray in Anvil (due to raised build height)
|
||||
|
||||
$nbt->setTag(new ListTag("Entities", $chunk->getNBTentities(), NBT::TAG_Compound));
|
||||
$nbt->setTag(new ListTag("TileEntities", $chunk->getNBTtiles(), NBT::TAG_Compound));
|
||||
|
||||
$writer = new BigEndianNbtSerializer();
|
||||
return $writer->writeCompressed(new CompoundTag("", [$nbt]), ZLIB_ENCODING_DEFLATE, RegionLoader::$COMPRESSION_LEVEL);
|
||||
throw new \RuntimeException("Unsupported");
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user