mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Block light bug fixes (#454)
* Fixed an age-old light calculation bug causing solid blocks to filter their own light, fixed #375, probably fixed #288
Light spread reduction should be done based on the _target's_ light filter level, not the source.
* Revert "Fix Glowing Obsidian lighting"
This hack is no longer necessary.
This reverts commit 35c33ba980
.
* Fixed wrong light levels for torch and redstone torch
* Take adjacent light levels and opacity changes into account, block light will now spread when an obstruction is removed, close #455
* Added timings for Level->setBlock() and lighting updates
This commit is contained in:
@ -1286,17 +1286,42 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
|
||||
public function updateBlockSkyLight(int $x, int $y, int $z){
|
||||
$this->timings->doBlockSkyLightUpdates->startTiming();
|
||||
//TODO
|
||||
$this->timings->doBlockSkyLightUpdates->stopTiming();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the highest light level available in the positions adjacent to the specified block coordinates.
|
||||
*
|
||||
* @param int $x
|
||||
* @param int $y
|
||||
* @param int $z
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHighestAdjacentBlockLight(int $x, int $y, int $z) : int{
|
||||
return max([
|
||||
$this->getBlockLightAt($x + 1, $y, $z),
|
||||
$this->getBlockLightAt($x - 1, $y, $z),
|
||||
$this->getBlockLightAt($x, $y + 1, $z),
|
||||
$this->getBlockLightAt($x, $y - 1, $z),
|
||||
$this->getBlockLightAt($x, $y, $z + 1),
|
||||
$this->getBlockLightAt($x, $y, $z - 1)
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateBlockLight(int $x, int $y, int $z){
|
||||
$this->timings->doBlockLightUpdates->startTiming();
|
||||
|
||||
$lightPropagationQueue = new \SplQueue();
|
||||
$lightRemovalQueue = new \SplQueue();
|
||||
$visited = [];
|
||||
$removalVisited = [];
|
||||
|
||||
$id = $this->getBlockIdAt($x, $y, $z);
|
||||
$oldLevel = $this->getBlockLightAt($x, $y, $z);
|
||||
$newLevel = (int) Block::$light[$this->getBlockIdAt($x, $y, $z)];
|
||||
$newLevel = max(Block::$light[$id], $this->getHighestAdjacentBlockLight($x, $y, $z) - Block::$lightFilter[$id]);
|
||||
|
||||
if($oldLevel !== $newLevel){
|
||||
$this->setBlockLightAt($x, $y, $z, $newLevel);
|
||||
@ -1328,7 +1353,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
/** @var Vector3 $node */
|
||||
$node = $lightPropagationQueue->dequeue();
|
||||
|
||||
$lightLevel = $this->getBlockLightAt($node->x, $node->y, $node->z) - (int) Block::$lightFilter[$this->getBlockIdAt($node->x, $node->y, $node->z)];
|
||||
$lightLevel = $this->getBlockLightAt($node->x, $node->y, $node->z);
|
||||
|
||||
if($lightLevel >= 1){
|
||||
$this->computeSpreadBlockLight($node->x - 1, $node->y, $node->z, $lightLevel, $lightPropagationQueue, $visited);
|
||||
@ -1339,6 +1364,8 @@ class Level implements ChunkManager, Metadatable{
|
||||
$this->computeSpreadBlockLight($node->x, $node->y, $node->z + 1, $lightLevel, $lightPropagationQueue, $visited);
|
||||
}
|
||||
}
|
||||
|
||||
$this->timings->doBlockLightUpdates->stopTiming();
|
||||
}
|
||||
|
||||
private function computeRemoveBlockLight(int $x, int $y, int $z, int $currentLight, \SplQueue $queue, \SplQueue $spreadQueue, array &$visited, array &$spreadVisited){
|
||||
@ -1365,6 +1392,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
private function computeSpreadBlockLight(int $x, int $y, int $z, int $currentLight, \SplQueue $queue, array &$visited){
|
||||
if($y < 0) return;
|
||||
$current = $this->getBlockLightAt($x, $y, $z);
|
||||
$currentLight -= Block::$lightFilter[$this->getBlockIdAt($x, $y, $z)];
|
||||
|
||||
if($current < $currentLight){
|
||||
$this->setBlockLightAt($x, $y, $z, $currentLight);
|
||||
@ -1402,6 +1430,8 @@ class Level implements ChunkManager, Metadatable{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->timings->setBlock->startTiming();
|
||||
|
||||
if($this->getChunk($pos->x >> 4, $pos->z >> 4, true)->setBlock($pos->x & 0x0f, $pos->y & Level::Y_MASK, $pos->z & 0x0f, $block->getId(), $block->getDamage())){
|
||||
if(!($pos instanceof Position)){
|
||||
$pos = $this->temporalPosition->setComponents($pos->x, $pos->y, $pos->z);
|
||||
@ -1441,9 +1471,13 @@ class Level implements ChunkManager, Metadatable{
|
||||
$this->updateAround($pos);
|
||||
}
|
||||
|
||||
$this->timings->setBlock->stopTiming();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->timings->setBlock->stopTiming();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user