diff --git a/src/block/Furnace.php b/src/block/Furnace.php index fbff73c93..7a64e3cd3 100644 --- a/src/block/Furnace.php +++ b/src/block/Furnace.php @@ -25,6 +25,7 @@ namespace pocketmine\block; use pocketmine\block\tile\Furnace as TileFurnace; use pocketmine\block\utils\FacesOppositePlacingPlayerTrait; +use pocketmine\block\utils\LightableTrait; use pocketmine\crafting\FurnaceType; use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\item\Item; @@ -34,11 +35,10 @@ use function mt_rand; class Furnace extends Opaque{ use FacesOppositePlacingPlayerTrait; + use LightableTrait; protected FurnaceType $furnaceType; - protected bool $lit = false; - public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, FurnaceType $furnaceType){ $this->furnaceType = $furnaceType; parent::__construct($idInfo, $name, $typeInfo); @@ -57,18 +57,6 @@ class Furnace extends Opaque{ return $this->lit ? 13 : 0; } - public function isLit() : bool{ - return $this->lit; - } - - /** - * @return $this - */ - public function setLit(bool $lit = true) : self{ - $this->lit = $lit; - return $this; - } - public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($player instanceof Player){ $furnace = $this->position->getWorld()->getTile($this->position); diff --git a/src/block/RedstoneOre.php b/src/block/RedstoneOre.php index 9e537bd27..10e701a6f 100644 --- a/src/block/RedstoneOre.php +++ b/src/block/RedstoneOre.php @@ -24,7 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\FortuneDropHelper; -use pocketmine\data\runtime\RuntimeDataDescriber; +use pocketmine\block\utils\LightableTrait; use pocketmine\item\Item; use pocketmine\item\VanillaItems; use pocketmine\math\Vector3; @@ -32,23 +32,7 @@ use pocketmine\player\Player; use function mt_rand; class RedstoneOre extends Opaque{ - protected bool $lit = false; - - protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->bool($this->lit); - } - - public function isLit() : bool{ - return $this->lit; - } - - /** - * @return $this - */ - public function setLit(bool $lit = true) : self{ - $this->lit = $lit; - return $this; - } + use LightableTrait; public function getLightLevel() : int{ return $this->lit ? 9 : 0; diff --git a/src/block/RedstoneTorch.php b/src/block/RedstoneTorch.php index b30c011d4..26c86038b 100644 --- a/src/block/RedstoneTorch.php +++ b/src/block/RedstoneTorch.php @@ -23,28 +23,22 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\LightableTrait; use pocketmine\data\runtime\RuntimeDataDescriber; class RedstoneTorch extends Torch{ - protected bool $lit = true; + use LightableTrait; + + public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo){ + $this->lit = true; + parent::__construct($idInfo, $name, $typeInfo); + } protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ parent::describeBlockOnlyState($w); $w->bool($this->lit); } - public function isLit() : bool{ - return $this->lit; - } - - /** - * @return $this - */ - public function setLit(bool $lit = true) : self{ - $this->lit = $lit; - return $this; - } - public function getLightLevel() : int{ return $this->lit ? 7 : 0; } diff --git a/src/block/utils/CandleTrait.php b/src/block/utils/CandleTrait.php index 58a7443a3..c9da97ee0 100644 --- a/src/block/utils/CandleTrait.php +++ b/src/block/utils/CandleTrait.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace pocketmine\block\utils; use pocketmine\block\Block; -use pocketmine\data\runtime\RuntimeDataDescriber; use pocketmine\entity\projectile\Projectile; use pocketmine\item\Durable; use pocketmine\item\enchantment\VanillaEnchantments; @@ -38,24 +37,12 @@ use pocketmine\world\sound\FireExtinguishSound; use pocketmine\world\sound\FlintSteelSound; trait CandleTrait{ - private bool $lit = false; - - protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{ - $w->bool($this->lit); - } + use LightableTrait; public function getLightLevel() : int{ return $this->lit ? 3 : 0; } - public function isLit() : bool{ return $this->lit; } - - /** @return $this */ - public function setLit(bool $lit) : self{ - $this->lit = $lit; - return $this; - } - /** @see Block::onInteract() */ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{ if($item->getTypeId() === ItemTypeIds::FIRE_CHARGE || $item->getTypeId() === ItemTypeIds::FLINT_AND_STEEL || $item->hasEnchantment(VanillaEnchantments::FIRE_ASPECT())){ diff --git a/src/block/utils/LightableTrait.php b/src/block/utils/LightableTrait.php new file mode 100644 index 000000000..51ce54f42 --- /dev/null +++ b/src/block/utils/LightableTrait.php @@ -0,0 +1,46 @@ +bool($this->lit); + } + + public function isLit() : bool{ + return $this->lit; + } + + /** + * @return $this + */ + public function setLit(bool $lit = true) : self{ + $this->lit = $lit; + return $this; + } +}