diff --git a/src/pocketmine/level/format/anvil/Chunk.php b/src/pocketmine/level/format/anvil/Chunk.php index c9bd003e7..221dc3128 100644 --- a/src/pocketmine/level/format/anvil/Chunk.php +++ b/src/pocketmine/level/format/anvil/Chunk.php @@ -160,6 +160,9 @@ class Chunk extends BaseChunk{ $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()), diff --git a/src/pocketmine/level/format/mcregion/Chunk.php b/src/pocketmine/level/format/mcregion/Chunk.php index 0463ac361..effdaed3a 100644 --- a/src/pocketmine/level/format/mcregion/Chunk.php +++ b/src/pocketmine/level/format/mcregion/Chunk.php @@ -70,6 +70,16 @@ class Chunk extends BaseFullChunk{ $this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 156, Binary::readInt("\x00\x85\xb2\x4a"))); } + if(!isset($this->nbt->Blocks)){ + $this->nbt->Blocks = new ByteArray("Blocks", str_repeat("\x00", 32768)); + } + + if(!isset($this->nbt->Data)){ + $this->nbt->Data = new ByteArray("Data", $half = str_repeat("\x00", 16384)); + $this->nbt->SkyLight = new ByteArray("SkyLight", $half); + $this->nbt->BlockLight = new ByteArray("BlockLight", $half); + } + parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $this->nbt["Blocks"], $this->nbt["Data"], $this->nbt["SkyLight"], $this->nbt["BlockLight"], $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue()); unset($this->nbt->Blocks); unset($this->nbt->Data); @@ -253,13 +263,15 @@ class Chunk extends BaseFullChunk{ $nbt->xPos = new Int("xPos", $this->x); $nbt->zPos = new Int("zPos", $this->z); - $nbt->Blocks = new ByteArray("Blocks", $this->getBlockIdArray()); - $nbt->Data = new ByteArray("Data", $this->getBlockDataArray()); - $nbt->SkyLight = new ByteArray("SkyLight", $this->getBlockSkyLightArray()); - $nbt->BlockLight = new ByteArray("BlockLight", $this->getBlockLightArray()); + if($this->isGenerated()){ + $nbt->Blocks = new ByteArray("Blocks", $this->getBlockIdArray()); + $nbt->Data = new ByteArray("Data", $this->getBlockDataArray()); + $nbt->SkyLight = new ByteArray("SkyLight", $this->getBlockSkyLightArray()); + $nbt->BlockLight = new ByteArray("BlockLight", $this->getBlockLightArray()); - $nbt->Biomes = new ByteArray("Biomes", $this->getBiomeIdArray()); - $nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray()); + $nbt->Biomes = new ByteArray("Biomes", $this->getBiomeIdArray()); + $nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray()); + } $entities = []; diff --git a/src/pocketmine/level/generator/GenerationManager.php b/src/pocketmine/level/generator/GenerationManager.php index d945ad988..b94d8d9a2 100644 --- a/src/pocketmine/level/generator/GenerationManager.php +++ b/src/pocketmine/level/generator/GenerationManager.php @@ -144,12 +144,17 @@ class GenerationManager{ $this->levels[$levelID]->populateChunk($chunkX, $chunkZ); //Request population directly if(isset($this->levels[$levelID])){ $this->generatedQueue[$levelID][$index] = true; - if(count($this->generatedQueue[$levelID]) > 6){ + if(count($this->generatedQueue[$levelID]) > 2){ foreach($this->levels[$levelID]->getChangedChunks() as $chunk){ - $this->sendChunk($levelID, $chunk); + if($chunk->isPopulated()){ + $this->sendChunk($levelID, $chunk); + } } - $this->levels[$levelID]->doGarbageCollection(); $this->levels[$levelID]->cleanChangedChunks(); + } + + if(count($this->generatedQueue[$levelID]) > 8){ + $this->levels[$levelID]->doGarbageCollection(); $this->generatedQueue[$levelID] = []; } }