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); $this->chunkLoadTask->setNextRun($this->chunkLoadTask->getNextRun() + 30);
return; return;
} }
unset($this->loadQueue[$index]); unset($this->loadQueue[$index]);
$this->usedChunks[$index] = [false, 0]; $this->usedChunks[$index] = [false, 0];

View File

@ -393,14 +393,16 @@ class Level implements ChunkManager, Metadatable{
foreach($this->usedChunks as $index => $p){ foreach($this->usedChunks as $index => $p){
Level::getXZ($index, $X, $Z); Level::getXZ($index, $X, $Z);
$chunk = $this->getChunkAt($X, $Z, true);
for($Y = 0; $Y < 8; ++$Y){ 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){ 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))); $x = mt_rand(0, 15);
if($block instanceof Block){ $y = mt_rand(0, 15);
if($block->onUpdate(self::BLOCK_UPDATE_RANDOM) === self::BLOCK_UPDATE_NORMAL){ $z = mt_rand(0, 15);
$this->updateAround($block, self::BLOCK_UPDATE_NORMAL); 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,8 +233,12 @@ abstract class BaseChunk implements Chunk{
} }
public function setSection($fY, ChunkSection $section){ public function setSection($fY, ChunkSection $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; $this->sections[(int) $fY] = $section;
} }
}
public function addEntity(Entity $entity){ public function addEntity(Entity $entity){
$this->entities[$entity->getID()] = $entity; $this->entities[$entity->getID()] = $entity;