mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 02:42:58 +00:00
Improved Anvil live conversion speed
This commit is contained in:
@ -152,6 +152,83 @@ class Chunk extends BaseChunk{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
* @param LevelProvider $provider
|
||||
*
|
||||
* @return Chunk
|
||||
*/
|
||||
public static function fromFastBinary($data, LevelProvider $provider = null){
|
||||
$nbt = new NBT(NBT::BIG_ENDIAN);
|
||||
|
||||
try{
|
||||
$nbt->read($data);
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
public function toFastBinary(){
|
||||
$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->Biomes = new ByteArray("Biomes", $this->getBiomeIdArray());
|
||||
$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);
|
||||
$writer = new NBT(NBT::BIG_ENDIAN);
|
||||
$nbt->setName("Level");
|
||||
$writer->setData(new Compound("", ["Level" => $nbt]));
|
||||
|
||||
return $writer->write();
|
||||
}
|
||||
|
||||
public function toBinary(){
|
||||
$nbt = clone $this->getNBT();
|
||||
|
||||
|
Reference in New Issue
Block a user