mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 10:53:05 +00:00
Moved light population to an async task when needed, improved empty chunks
This commit is contained in:
@ -31,6 +31,7 @@ use pocketmine\nbt\tag\Compound;
|
||||
use pocketmine\nbt\tag\Enum;
|
||||
use pocketmine\nbt\tag\Int;
|
||||
use pocketmine\nbt\tag\IntArray;
|
||||
use pocketmine\nbt\tag\Long;
|
||||
use pocketmine\Player;
|
||||
use pocketmine\utils\Binary;
|
||||
|
||||
|
@ -164,12 +164,6 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
|
||||
$this->isInit = true;
|
||||
}
|
||||
|
||||
if(!$this->isLightPopulated() and $this->isPopulated()){
|
||||
$this->recalculateHeightMap();
|
||||
$this->populateSkyLight();
|
||||
$this->setLightPopulated();
|
||||
}
|
||||
}
|
||||
|
||||
public function getX(){
|
||||
|
@ -109,7 +109,7 @@ class EmptyChunkSection implements ChunkSection{
|
||||
}
|
||||
|
||||
final public function getBlockSkyLight($x, $y, $z){
|
||||
return 0;
|
||||
return 15;
|
||||
}
|
||||
|
||||
final public function setBlockSkyLight($x, $y, $z, $level){
|
||||
|
@ -29,6 +29,9 @@ use pocketmine\utils\Binary;
|
||||
|
||||
class Chunk extends BaseFullChunk{
|
||||
|
||||
const DATA_LENGTH = 16384 * (2 + 1 + 1 + 1) + 256 + 1024;
|
||||
|
||||
protected $isLightPopulated = false;
|
||||
protected $isPopulated = false;
|
||||
protected $isGenerated = false;
|
||||
|
||||
@ -195,6 +198,20 @@ class Chunk extends BaseFullChunk{
|
||||
return substr($this->blockLight, ($x << 10) + ($z << 6), 64);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isLightPopulated(){
|
||||
return $this->isLightPopulated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $value
|
||||
*/
|
||||
public function setLightPopulated($value = 1){
|
||||
$this->isLightPopulated = (bool) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
@ -350,7 +367,9 @@ class Chunk extends BaseFullChunk{
|
||||
*/
|
||||
public static function getEmptyChunk($chunkX, $chunkZ, LevelProvider $provider = null){
|
||||
try{
|
||||
return new Chunk($provider instanceof LevelProvider ? $provider : LevelDB::class, $chunkX, $chunkZ, str_repeat("\x00", 16384 * (2 + 1 + 1 + 1) + 256 + 1024));
|
||||
$chunk = new Chunk($provider instanceof LevelProvider ? $provider : LevelDB::class, $chunkX, $chunkZ, str_repeat("\x00", self::DATA_LENGTH));
|
||||
$chunk->skyLight = str_repeat("\xff", 16384);
|
||||
return $chunk;
|
||||
}catch(\Exception $e){
|
||||
return null;
|
||||
}
|
||||
|
@ -238,7 +238,7 @@ class Chunk extends BaseFullChunk{
|
||||
}
|
||||
|
||||
public function setLightPopulated($value = 1){
|
||||
$this->nbt->LightPopulated = new Byte("LightPopulated", $value);
|
||||
$this->nbt->LightPopulated = new Byte("LightPopulated", $value ? 1 : 0);
|
||||
$this->hasChanged = true;
|
||||
}
|
||||
|
||||
@ -253,7 +253,7 @@ class Chunk extends BaseFullChunk{
|
||||
* @param int $value
|
||||
*/
|
||||
public function setPopulated($value = 1){
|
||||
$this->nbt->TerrainPopulated = new Byte("TerrainPopulated", (int) $value);
|
||||
$this->nbt->TerrainPopulated = new Byte("TerrainPopulated", $value ? 1 : 0);
|
||||
$this->hasChanged = true;
|
||||
}
|
||||
|
||||
@ -428,7 +428,7 @@ class Chunk extends BaseFullChunk{
|
||||
|
||||
$chunk->data = str_repeat("\x00", 16384);
|
||||
$chunk->blocks = $chunk->data . $chunk->data;
|
||||
$chunk->skyLight = $chunk->data;
|
||||
$chunk->skyLight = str_repeat("\xff", 16384);
|
||||
$chunk->blockLight = $chunk->data;
|
||||
|
||||
$chunk->heightMap = array_fill(0, 256, 0);
|
||||
|
Reference in New Issue
Block a user