mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-19 18:04:07 +00:00
I accidentally added this during a separation of my local changes, but it's useful anyway, so we should use it. This removes BlockLightUpdate's implicit dependency on Block, which is a step towards native light.
59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
|
|
/*
|
|
*
|
|
* ____ _ _ __ __ _ __ __ ____
|
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* @author PocketMine Team
|
|
* @link http://www.pocketmine.net/
|
|
*
|
|
*
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\world\light;
|
|
|
|
use pocketmine\world\ChunkManager;
|
|
use function max;
|
|
|
|
class BlockLightUpdate extends LightUpdate{
|
|
|
|
/**
|
|
* @var \SplFixedArray|int[]
|
|
* @phpstan-var \SplFixedArray<int>
|
|
*/
|
|
private $lightEmitters;
|
|
|
|
/**
|
|
* @param \SplFixedArray|int[] $lightFilters
|
|
* @param \SplFixedArray|int[] $lightEmitters
|
|
* @phpstan-param \SplFixedArray<int> $lightFilters
|
|
* @phpstan-param \SplFixedArray<int> $lightEmitters
|
|
*/
|
|
public function __construct(ChunkManager $world, \SplFixedArray $lightFilters, \SplFixedArray $lightEmitters){
|
|
parent::__construct($world, $lightFilters);
|
|
$this->lightEmitters = $lightEmitters;
|
|
}
|
|
|
|
protected function updateLightArrayRef() : void{
|
|
$this->currentLightArray = $this->subChunkHandler->currentSubChunk->getBlockLightArray();
|
|
}
|
|
|
|
public function recalculateNode(int $x, int $y, int $z) : void{
|
|
if($this->subChunkHandler->moveTo($x, $y, $z, false)){
|
|
$block = $this->subChunkHandler->currentSubChunk->getFullBlock($x & 0xf, $y & 0xf, $z & 0xf);
|
|
$this->setAndUpdateLight($x, $y, $z, max($this->lightEmitters[$block], $this->getHighestAdjacentLight($x, $y, $z) - $this->lightFilters[$block]));
|
|
}
|
|
}
|
|
}
|