mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 02:42:58 +00:00
Fix some of the implicit immutability issues of EmptySubChunk
it's useful to have an immutable stub around for the sake of feeding back dummy read values, but for write values it has to barf instead of being quiet. There's still some issues with LightArray which I don't currently have a solution for, but I'm thinking about separating light storage from chunks anyway.
This commit is contained in:
@ -152,7 +152,7 @@ class Chunk{
|
||||
* Sets the blockstate at the given coordinate by internal ID.
|
||||
*/
|
||||
public function setFullBlock(int $x, int $y, int $z, int $block) : void{
|
||||
$this->getSubChunk($y >> 4)->setFullBlock($x, $y & 0xf, $z, $block);
|
||||
$this->getWritableSubChunk($y >> 4)->setFullBlock($x, $y & 0xf, $z, $block);
|
||||
$this->dirtyFlags |= self::DIRTY_FLAG_TERRAIN;
|
||||
}
|
||||
|
||||
@ -178,12 +178,12 @@ class Chunk{
|
||||
* @param int $level 0-15
|
||||
*/
|
||||
public function setBlockSkyLight(int $x, int $y, int $z, int $level) : void{
|
||||
$this->getSubChunk($y >> 4)->getBlockSkyLightArray()->set($x & 0xf, $y & 0x0f, $z & 0xf, $level);
|
||||
$this->getWritableSubChunk($y >> 4)->getBlockSkyLightArray()->set($x & 0xf, $y & 0x0f, $z & 0xf, $level);
|
||||
}
|
||||
|
||||
public function setAllBlockSkyLight(int $level) : void{
|
||||
for($y = $this->subChunks->count() - 1; $y >= 0; --$y){
|
||||
$this->getSubChunk($y)->setBlockSkyLightArray(LightArray::fill($level));
|
||||
$this->getWritableSubChunk($y)->setBlockSkyLightArray(LightArray::fill($level));
|
||||
}
|
||||
}
|
||||
|
||||
@ -209,12 +209,12 @@ class Chunk{
|
||||
* @param int $level 0-15
|
||||
*/
|
||||
public function setBlockLight(int $x, int $y, int $z, int $level) : void{
|
||||
$this->getSubChunk($y >> 4)->getBlockLightArray()->set($x & 0xf, $y & 0x0f, $z & 0xf, $level);
|
||||
$this->getWritableSubChunk($y >> 4)->getBlockLightArray()->set($x & 0xf, $y & 0x0f, $z & 0xf, $level);
|
||||
}
|
||||
|
||||
public function setAllBlockLight(int $level) : void{
|
||||
for($y = $this->subChunks->count() - 1; $y >= 0; --$y){
|
||||
$this->getSubChunk($y)->setBlockLightArray(LightArray::fill($level));
|
||||
$this->getWritableSubChunk($y)->setBlockLightArray(LightArray::fill($level));
|
||||
}
|
||||
}
|
||||
|
||||
@ -340,10 +340,10 @@ class Chunk{
|
||||
$highestHeightMap = max($this->heightMap->getValues());
|
||||
$lowestFullyLitSubChunk = ($highestHeightMap >> 4) + (($highestHeightMap & 0xf) !== 0 ? 1 : 0);
|
||||
for($y = 0; $y < $lowestFullyLitSubChunk; $y++){
|
||||
$this->getSubChunk($y)->setBlockSkyLightArray(LightArray::fill(0));
|
||||
$this->getWritableSubChunk($y)->setBlockSkyLightArray(LightArray::fill(0));
|
||||
}
|
||||
for($y = $lowestFullyLitSubChunk, $yMax = $this->subChunks->count(); $y < $yMax; $y++){
|
||||
$this->getSubChunk($y)->setBlockSkyLightArray(LightArray::fill(15));
|
||||
$this->getWritableSubChunk($y)->setBlockSkyLightArray(LightArray::fill(15));
|
||||
}
|
||||
|
||||
for($x = 0; $x < 16; ++$x){
|
||||
@ -623,6 +623,13 @@ class Chunk{
|
||||
return $this->subChunks[$y];
|
||||
}
|
||||
|
||||
public function getWritableSubChunk(int $y) : SubChunk{
|
||||
if($y < 0 || $y >= $this->subChunks->getSize()){
|
||||
throw new \InvalidArgumentException("Cannot get subchunk $y for writing");
|
||||
}
|
||||
return $this->subChunks[$y];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a subchunk in the chunk index
|
||||
*/
|
||||
|
Reference in New Issue
Block a user