22declare(strict_types=1);
27use pocketmine\block\utils\HorizontalFacingTrait;
28use pocketmine\block\utils\StaticSupportTrait;
38 use HorizontalFacingTrait;
39 use StaticSupportTrait {
43 public const MIN_COUNT = 1;
44 public const MAX_COUNT = 4;
46 protected int $count = self::MIN_COUNT;
49 $w->horizontalFacing($this->facing);
50 $w->
boundedIntAuto(self::MIN_COUNT, self::MAX_COUNT, $this->count);
53 public function getCount() : int{
59 if($count < self::MIN_COUNT || $count > self::MAX_COUNT){
60 throw new \InvalidArgumentException(
"Count must be in range " . self::MIN_COUNT .
" ... " . self::MAX_COUNT);
62 $this->count = $count;
66 private function canBeSupportedAt(Block $block) : bool{
67 $supportBlock = $block->getSide(Facing::DOWN);
69 return $supportBlock->hasTypeTag(BlockTypeTags::DIRT) || $supportBlock->hasTypeTag(BlockTypeTags::MUD);
73 return ($blockReplace instanceof
PinkPetals && $blockReplace->count < self::MAX_COUNT) || $this->supportedWhenPlacedAt($blockReplace, $clickVector, $face, $isClickedBlock);
77 if($blockReplace instanceof
PinkPetals && $blockReplace->count < self::MAX_COUNT){
78 $this->count = $blockReplace->count + 1;
79 $this->facing = $blockReplace->facing;
80 }elseif($player !==
null){
81 $this->facing = Facing::opposite($player->getHorizontalFacing());
83 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
89 if($this->count < self::MAX_COUNT){
90 $grew = BlockEventHelper::grow($this, (clone $this)->setCount($this->count + 1), $player);
92 $this->position->getWorld()->dropItem($this->position->add(0, 0.5, 0), $this->asItem());
112 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)