22declare(strict_types=1);
27use pocketmine\block\utils\StaticSupportTrait;
36 use StaticSupportTrait;
38 protected ?
Block $plant =
null;
42 $tile = $this->position->getWorld()->getTile($this->position);
43 if($tile instanceof TileFlowerPot){
53 parent::writeStateToWorld();
55 $tile = $this->position->getWorld()->getTile($this->position);
56 assert($tile instanceof TileFlowerPot);
57 $tile->setPlant($this->plant);
60 public function getPlant() : ?
Block{
66 if($plant === null || $plant instanceof
Air){
69 $this->plant = clone $plant;
74 public function canAddPlant(Block $block) : bool{
75 if($this->plant !== null){
79 return $this->isValidPlant($block);
82 private function isValidPlant(Block $block) : bool{
83 return $block->hasTypeTag(BlockTypeTags::POTTABLE_PLANTS);
93 private function canBeSupportedAt(
Block $block) : bool{
94 return $block->getAdjacentSupportType(
Facing::DOWN)->hasCenterSupport();
98 $world = $this->position->getWorld();
100 if($this->plant !==
null){
101 if($this->isValidPlant($plant)){
107 $removedItems = [$this->plant->asItem()];
108 if($player !==
null){
111 $removedItems = $player->getInventory()->addItem(...$removedItems);
113 foreach($removedItems as $drops){
114 $world->dropItem($this->position->add(0.5, 0.5, 0.5), $drops);
117 $this->setPlant(
null);
118 $world->setBlock($this->position, $this);
120 }elseif($this->isValidPlant($plant)){
121 $this->setPlant($plant);
123 $world->setBlock($this->position, $this);
132 $items = parent::getDropsForCompatibleTool($item);
133 if($this->plant !==
null){
134 $items[] = $this->plant->asItem();
141 return $this->plant !== null ? $this->plant->asItem() : parent::getPickedItem($addUserData);
recalculateCollisionBoxes()
getDropsForCompatibleTool(Item $item)
getPickedItem(bool $addUserData=false)
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
getBlock(?int $clickedFace=null)