Added Empty chunk detection

This commit is contained in:
Shoghi Cervantes 2014-06-22 22:29:46 +02:00
parent 36cdfd969d
commit 6f9becdbb3
3 changed files with 14 additions and 7 deletions

View File

@ -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];

View File

@ -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);
}
}
}

View File

@ -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){