From 4fc712119fa2160c0b43a43f8092d96789c8f7c5 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 8 Apr 2022 23:07:08 +0100 Subject: [PATCH] FlowerPot: allow removing the planted item closes #4896 closes #4898 this is not completely consistent with client-side predictions due to a bug in the client, which I believe is a problem limited to the legacy transaction system. --- src/block/FlowerPot.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/block/FlowerPot.php b/src/block/FlowerPot.php index 6dc21eb44..a9ac97b34 100644 --- a/src/block/FlowerPot.php +++ b/src/block/FlowerPot.php @@ -82,6 +82,10 @@ class FlowerPot extends Flowable{ return false; } + return $this->isValidPlant($block); + } + + private function isValidPlant(Block $block) : bool{ return $block instanceof Cactus || $block instanceof DeadBush || @@ -115,8 +119,26 @@ class FlowerPot extends Flowable{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $plant = $item->getBlock(); - if(!$this->canAddPlant($plant)){ - return false; + if($this->plant !== null){ + if($this->isValidPlant($plant)){ + //for some reason, vanilla doesn't remove the contents of the pot if the held item is plantable + //and will also cause a new plant to be placed if clicking on the side + return false; + } + + $removedItems = [$this->plant->asItem()]; + if($player !== null){ + //this one just has to be a weirdo :( + //this is the only block that directly adds items to the player inventory instead of just dropping items + $removedItems = $player->getInventory()->addItem(...$removedItems); + } + foreach($removedItems as $drops){ + $this->position->getWorld()->dropItem($this->position->add(0.5, 0.5, 0.5), $drops); + } + + $this->setPlant(null); + $this->position->getWorld()->setBlock($this->position, $this); + return true; } $this->setPlant($plant);