mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-26 21:03:45 +00:00
DaylightSensor: refactor power -> signalStrength
This commit is contained in:
parent
4fc3bc53f7
commit
02b0036cbe
@ -39,7 +39,7 @@ class DaylightSensor extends Transparent{
|
|||||||
protected $idInfo;
|
protected $idInfo;
|
||||||
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
protected $power = 0;
|
protected $signalStrength = 0;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $inverted = false;
|
protected $inverted = false;
|
||||||
@ -53,11 +53,11 @@ class DaylightSensor extends Transparent{
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function writeStateToMeta() : int{
|
protected function writeStateToMeta() : int{
|
||||||
return $this->power;
|
return $this->signalStrength;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||||
$this->power = BlockDataSerializer::readBoundedInt("power", $stateMeta, 0, 15);
|
$this->signalStrength = BlockDataSerializer::readBoundedInt("signalStrength", $stateMeta, 0, 15);
|
||||||
$this->inverted = $id === $this->idInfo->getSecondId();
|
$this->inverted = $id === $this->idInfo->getSecondId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,21 +90,21 @@ class DaylightSensor extends Transparent{
|
|||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
$this->inverted = !$this->inverted;
|
$this->inverted = !$this->inverted;
|
||||||
$this->power = $this->recalculatePower();
|
$this->signalStrength = $this->recalculateSignalStrength();
|
||||||
$this->pos->getWorld()->setBlock($this->pos, $this);
|
$this->pos->getWorld()->setBlock($this->pos, $this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onScheduledUpdate() : void{
|
public function onScheduledUpdate() : void{
|
||||||
$newPower = $this->recalculatePower();
|
$signalStrength = $this->recalculateSignalStrength();
|
||||||
if($this->power !== $newPower){
|
if($this->signalStrength !== $signalStrength){
|
||||||
$this->power = $newPower;
|
$this->signalStrength = $signalStrength;
|
||||||
$this->pos->getWorld()->setBlock($this->pos, $this);
|
$this->pos->getWorld()->setBlock($this->pos, $this);
|
||||||
}
|
}
|
||||||
$this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, 20);
|
$this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function recalculatePower() : int{
|
private function recalculateSignalStrength() : int{
|
||||||
$lightLevel = $this->pos->getWorld()->getRealBlockSkyLightAt($this->pos->x, $this->pos->y, $this->pos->z);
|
$lightLevel = $this->pos->getWorld()->getRealBlockSkyLightAt($this->pos->x, $this->pos->y, $this->pos->z);
|
||||||
if($this->inverted){
|
if($this->inverted){
|
||||||
return 15 - $lightLevel;
|
return 15 - $lightLevel;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user