From 6f9becdbb330243097056fee71423217c543b6af Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sun, 22 Jun 2014 22:29:46 +0200 Subject: [PATCH] Added Empty chunk detection --- src/pocketmine/Player.php | 1 + src/pocketmine/level/Level.php | 14 ++++++++------ src/pocketmine/level/format/generic/BaseChunk.php | 6 +++++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index e69e2648c..81cde18d4 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -568,6 +568,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ $this->chunkLoadTask->setNextRun($this->chunkLoadTask->getNextRun() + 30); return; } + unset($this->loadQueue[$index]); $this->usedChunks[$index] = [false, 0]; diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index a505efedc..da1991fb3 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -393,14 +393,16 @@ class Level implements ChunkManager, Metadatable{ foreach($this->usedChunks as $index => $p){ Level::getXZ($index, $X, $Z); + $chunk = $this->getChunkAt($X, $Z, true); for($Y = 0; $Y < 8; ++$Y){ - if(!$this->getChunkAt($X, $Z, true)->isSectionEmpty($Y)){ + if(!$chunk->isSectionEmpty($Y)){ + $section = $chunk->getSection($Y); for($i = 0; $i < 3; ++$i){ - $block = $this->getBlock(new Vector3(($X << 4) + mt_rand(0, 15), ($Y << 4) + mt_rand(0, 15), ($Z << 4) + mt_rand(0, 15))); - if($block instanceof Block){ - if($block->onUpdate(self::BLOCK_UPDATE_RANDOM) === self::BLOCK_UPDATE_NORMAL){ - $this->updateAround($block, self::BLOCK_UPDATE_NORMAL); - } + $x = mt_rand(0, 15); + $y = mt_rand(0, 15); + $z = mt_rand(0, 15); + if($section->getBlockId($x, $y, $z) !== 0){ + $this->getBlock(new Vector3($X * 16 + $x, $Y * 16 + $y, $Z * 16 + $z))->onUpdate(self::BLOCK_UPDATE_RANDOM); } } } diff --git a/src/pocketmine/level/format/generic/BaseChunk.php b/src/pocketmine/level/format/generic/BaseChunk.php index 67198339f..59456d4d2 100644 --- a/src/pocketmine/level/format/generic/BaseChunk.php +++ b/src/pocketmine/level/format/generic/BaseChunk.php @@ -233,7 +233,11 @@ abstract class BaseChunk implements Chunk{ } public function setSection($fY, ChunkSection $section){ - $this->sections[(int) $fY] = $section; + if(substr_count($section->getIdArray(), "\x00") === 4096 and substr_count($section->getDataArray(), "\x00") === 2048){ + $this->sections[(int) $fY] = new EmptyChunkSection($fY); + }else{ + $this->sections[(int) $fY] = $section; + } } public function addEntity(Entity $entity){