mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-11 05:55:33 +00:00
Added AnalogRedstoneSignalEmitterTrait
This commit is contained in:
parent
02b0036cbe
commit
48ef8771cd
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait;
|
||||
use pocketmine\block\utils\BlockDataSerializer;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
@ -35,12 +36,11 @@ use function round;
|
||||
use const M_PI;
|
||||
|
||||
class DaylightSensor extends Transparent{
|
||||
use AnalogRedstoneSignalEmitterTrait;
|
||||
|
||||
/** @var BlockIdentifierFlattened */
|
||||
protected $idInfo;
|
||||
|
||||
/** @var int */
|
||||
protected $signalStrength = 0;
|
||||
|
||||
/** @var bool */
|
||||
protected $inverted = false;
|
||||
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\tile\Comparator;
|
||||
use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait;
|
||||
use pocketmine\block\utils\BlockDataSerializer;
|
||||
use pocketmine\block\utils\HorizontalFacingTrait;
|
||||
use pocketmine\item\Item;
|
||||
@ -36,6 +37,7 @@ use function assert;
|
||||
|
||||
class RedstoneComparator extends Flowable{
|
||||
use HorizontalFacingTrait;
|
||||
use AnalogRedstoneSignalEmitterTrait;
|
||||
|
||||
/** @var BlockIdentifierFlattened */
|
||||
protected $idInfo;
|
||||
@ -44,8 +46,6 @@ class RedstoneComparator extends Flowable{
|
||||
protected $isSubtractMode = false;
|
||||
/** @var bool */
|
||||
protected $powered = false;
|
||||
/** @var int */
|
||||
protected $signalStrength = 0;
|
||||
|
||||
public function __construct(BlockIdentifierFlattened $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||
parent::__construct($idInfo, $name, $breakInfo ?? BlockBreakInfo::instant());
|
||||
@ -106,16 +106,6 @@ class RedstoneComparator extends Flowable{
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSignalStrength() : int{
|
||||
return $this->signalStrength;
|
||||
}
|
||||
|
||||
/** @return $this */
|
||||
public function setSignalStrength(int $signalStrength) : self{
|
||||
$this->signalStrength = $signalStrength;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AxisAlignedBB[]
|
||||
*/
|
||||
|
@ -23,23 +23,22 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait;
|
||||
use pocketmine\block\utils\BlockDataSerializer;
|
||||
|
||||
class RedstoneWire extends Flowable{
|
||||
|
||||
/** @var int */
|
||||
protected $power = 0;
|
||||
use AnalogRedstoneSignalEmitterTrait;
|
||||
|
||||
public function __construct(BlockIdentifier $idInfo, string $name, ?BlockBreakInfo $breakInfo = null){
|
||||
parent::__construct($idInfo, $name, $breakInfo ?? BlockBreakInfo::instant());
|
||||
}
|
||||
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
$this->power = BlockDataSerializer::readBoundedInt("power", $stateMeta, 0, 15);
|
||||
$this->signalStrength = BlockDataSerializer::readBoundedInt("signalStrength", $stateMeta, 0, 15);
|
||||
}
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
return $this->power;
|
||||
return $this->signalStrength;
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
|
@ -23,19 +23,18 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait;
|
||||
use pocketmine\block\utils\BlockDataSerializer;
|
||||
|
||||
abstract class WeightedPressurePlate extends PressurePlate{
|
||||
|
||||
/** @var int */
|
||||
protected $power = 0;
|
||||
use AnalogRedstoneSignalEmitterTrait;
|
||||
|
||||
protected function writeStateToMeta() : int{
|
||||
return $this->power;
|
||||
return $this->signalStrength;
|
||||
}
|
||||
|
||||
public function readStateFromData(int $id, int $stateMeta) : void{
|
||||
$this->power = BlockDataSerializer::readBoundedInt("power", $stateMeta, 0, 15);
|
||||
$this->signalStrength = BlockDataSerializer::readBoundedInt("signalStrength", $stateMeta, 0, 15);
|
||||
}
|
||||
|
||||
public function getStateBitmask() : int{
|
||||
|
39
src/block/utils/AnalogRedstoneSignalEmitterTrait.php
Normal file
39
src/block/utils/AnalogRedstoneSignalEmitterTrait.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?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\block\utils;
|
||||
|
||||
trait AnalogRedstoneSignalEmitterTrait{
|
||||
protected int $signalStrength = 0;
|
||||
|
||||
public function getOutputSignalStrength() : int{ return $this->signalStrength; }
|
||||
|
||||
/** @return $this */
|
||||
public function setOutputSignalStrength(int $signalStrength) : self{
|
||||
if($signalStrength < 0 || $signalStrength > 15){
|
||||
throw new \InvalidArgumentException("Signal strength must be in range 0-15");
|
||||
}
|
||||
$this->signalStrength = $signalStrength;
|
||||
return $this;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user