22declare(strict_types=1);
28use pocketmine\block\utils\HorizontalFacingOption;
29use pocketmine\block\utils\HorizontalFacingTrait;
30use pocketmine\block\utils\StaticSupportTrait;
40 use HorizontalFacingTrait;
41 use StaticSupportTrait {
45 public const MIN_COUNT = 1;
46 public const MAX_COUNT = 4;
48 protected int $count = self::MIN_COUNT;
51 $w->enum($this->facing);
52 $w->
boundedIntAuto(self::MIN_COUNT, self::MAX_COUNT, $this->count);
55 public function getCount() : int{
61 if($count < self::MIN_COUNT || $count > self::MAX_COUNT){
62 throw new \InvalidArgumentException(
"Count must be in range " . self::MIN_COUNT .
" ... " . self::MAX_COUNT);
64 $this->count = $count;
68 private function canBeSupportedAt(Block $block) : bool{
69 $supportBlock = $block->getSide(Facing::DOWN);
71 return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD);
75 return ($blockReplace instanceof
PinkPetals && $blockReplace->count < self::MAX_COUNT) || $this->supportedWhenPlacedAt($blockReplace, $clickVector, $face, $isClickedBlock);
79 if($blockReplace instanceof
PinkPetals && $blockReplace->count < self::MAX_COUNT){
80 $this->count = $blockReplace->count + 1;
81 $this->facing = $blockReplace->facing;
82 }elseif($player !==
null){
83 $this->facing = HorizontalFacingOption::fromFacing(Facing::opposite($player->getHorizontalFacing()));
85 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
91 if($this->count < self::MAX_COUNT){
92 $grew = BlockEventHelper::grow($this, (clone $this)->setCount($this->count + 1), $player);
94 $this->position->getWorld()->dropItem($this->position->add(0, 0.5, 0), $this->asItem());
114 return [$this->asItem()->setCount($this->count)];
describeBlockOnlyState(RuntimeDataDescriber $w)
onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
getDropsForCompatibleTool(Item $item)
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, Facing $face, Vector3 $clickVector, ?Player $player=null)
canBePlacedAt(Block $blockReplace, Vector3 $clickVector, Facing $face, bool $isClickedBlock)
boundedIntAuto(int $min, int $max, int &$value)