diff --git a/src/block/BaseCoral.php b/src/block/BaseCoral.php index f3b37988a..71b1a5880 100644 --- a/src/block/BaseCoral.php +++ b/src/block/BaseCoral.php @@ -24,34 +24,17 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\CoralType; +use pocketmine\block\utils\CoralTypeTrait; use pocketmine\item\Item; abstract class BaseCoral extends Transparent{ - - protected CoralType $coralType; - protected bool $dead = false; + use CoralTypeTrait; public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo){ parent::__construct($idInfo, $name, $breakInfo); $this->coralType = CoralType::TUBE(); } - public function getCoralType() : CoralType{ return $this->coralType; } - - /** @return $this */ - public function setCoralType(CoralType $coralType) : self{ - $this->coralType = $coralType; - return $this; - } - - public function isDead() : bool{ return $this->dead; } - - /** @return $this */ - public function setDead(bool $dead) : self{ - $this->dead = $dead; - return $this; - } - public function onNearbyBlockChange() : void{ if(!$this->dead){ $world = $this->position->getWorld(); diff --git a/src/block/CoralBlock.php b/src/block/CoralBlock.php index 5399e5804..f06172be5 100644 --- a/src/block/CoralBlock.php +++ b/src/block/CoralBlock.php @@ -24,15 +24,14 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\block\utils\CoralType; +use pocketmine\block\utils\CoralTypeTrait; use pocketmine\block\utils\InvalidBlockStateException; use pocketmine\data\bedrock\CoralTypeIdMap; use pocketmine\item\Item; use function mt_rand; final class CoralBlock extends Opaque{ - - private CoralType $coralType; - private bool $dead = false; + use CoralTypeTrait; public function __construct(BlockIdentifier $idInfo, string $name, BlockBreakInfo $breakInfo){ $this->coralType = CoralType::TUBE(); @@ -60,22 +59,6 @@ final class CoralBlock extends Opaque{ return 0b1111; } - public function getCoralType() : CoralType{ return $this->coralType; } - - /** @return $this */ - public function setCoralType(CoralType $coralType) : self{ - $this->coralType = $coralType; - return $this; - } - - public function isDead() : bool{ return $this->dead; } - - /** @return $this */ - public function setDead(bool $dead) : self{ - $this->dead = $dead; - return $this; - } - public function onNearbyBlockChange() : void{ if(!$this->dead){ $this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, mt_rand(40, 200)); diff --git a/src/block/utils/CoralTypeTrait.php b/src/block/utils/CoralTypeTrait.php new file mode 100644 index 000000000..33a37bc55 --- /dev/null +++ b/src/block/utils/CoralTypeTrait.php @@ -0,0 +1,46 @@ +coralType; } + + /** @return $this */ + public function setCoralType(CoralType $coralType) : self{ + $this->coralType = $coralType; + return $this; + } + + public function isDead() : bool{ return $this->dead; } + + /** @return $this */ + public function setDead(bool $dead) : self{ + $this->dead = $dead; + return $this; + } +}