22declare(strict_types=1);
28use pocketmine\block\utils\HorizontalFacingTrait;
29use pocketmine\block\utils\StaticSupportTrait;
39 use HorizontalFacingTrait;
40 use StaticSupportTrait {
44 public const MIN_COUNT = 1;
45 public const MAX_COUNT = 4;
47 protected int $count = self::MIN_COUNT;
50 $w->horizontalFacing($this->facing);
51 $w->
boundedIntAuto(self::MIN_COUNT, self::MAX_COUNT, $this->count);
54 public function getCount() : int{
60 if($count < self::MIN_COUNT || $count > self::MAX_COUNT){
61 throw new \InvalidArgumentException(
"Count must be in range " . self::MIN_COUNT .
" ... " . self::MAX_COUNT);
63 $this->count = $count;
67 private function canBeSupportedAt(Block $block) : bool{
68 $supportBlock = $block->getSide(Facing::DOWN);
70 return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD);
74 return ($blockReplace instanceof
PinkPetals && $blockReplace->count < self::MAX_COUNT) || $this->supportedWhenPlacedAt($blockReplace, $clickVector, $face, $isClickedBlock);
78 if($blockReplace instanceof
PinkPetals && $blockReplace->count < self::MAX_COUNT){
79 $this->count = $blockReplace->count + 1;
80 $this->facing = $blockReplace->facing;
81 }elseif($player !==
null){
82 $this->facing = Facing::opposite($player->getHorizontalFacing());
84 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
90 if($this->count < self::MAX_COUNT){
91 $grew = BlockEventHelper::grow($this, (clone $this)->setCount($this->count + 1), $player);
93 $this->position->getWorld()->dropItem($this->position->add(0, 0.5, 0), $this->asItem());
113 return [$this->asItem()->setCount($this->count)];
describeBlockOnlyState(RuntimeDataDescriber $w)
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
getDropsForCompatibleTool(Item $item)
canBePlacedAt(Block $blockReplace, Vector3 $clickVector, int $face, bool $isClickedBlock)
boundedIntAuto(int $min, int $max, int &$value)