From 07b1cff30609e3e11360cdb4403d4757918559c7 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 5 Nov 2021 17:15:55 +0100 Subject: [PATCH] Bonemeal is no longer consumed when cancelling plant growth events (#4551) --- src/block/Crops.php | 3 +-- src/block/Sapling.php | 11 +++++------ src/block/Sugarcane.php | 11 ++++++----- src/block/SweetBerryBush.php | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/block/Crops.php b/src/block/Crops.php index 47cb33897..c7f201b41 100644 --- a/src/block/Crops.php +++ b/src/block/Crops.php @@ -80,10 +80,9 @@ abstract class Crops extends Flowable{ $ev->call(); if(!$ev->isCancelled()){ $this->position->getWorld()->setBlock($this->position, $ev->getNewState()); + $item->pop(); } - $item->pop(); - return true; } diff --git a/src/block/Sapling.php b/src/block/Sapling.php index d2ae0b5a7..85e092451 100644 --- a/src/block/Sapling.php +++ b/src/block/Sapling.php @@ -76,9 +76,7 @@ class Sapling extends Flowable{ } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ - if($item instanceof Fertilizer){ - $this->grow($player); - + if($item instanceof Fertilizer && $this->grow($player)){ $item->pop(); return true; @@ -108,19 +106,20 @@ class Sapling extends Flowable{ } } - private function grow(?Player $player) : void{ + private function grow(?Player $player) : bool{ $random = new Random(mt_rand()); $tree = TreeFactory::get($random, $this->treeType); $transaction = $tree?->getBlockTransaction($this->position->getWorld(), $this->position->getFloorX(), $this->position->getFloorY(), $this->position->getFloorZ(), $random); if($transaction === null){ - return; + return false; } $ev = new StructureGrowEvent($this, $transaction, $player); $ev->call(); if(!$ev->isCancelled()){ - $transaction->apply(); + return $transaction->apply(); } + return false; } public function getFuelTime() : int{ diff --git a/src/block/Sugarcane.php b/src/block/Sugarcane.php index eadf9c1ff..90eef3d4b 100644 --- a/src/block/Sugarcane.php +++ b/src/block/Sugarcane.php @@ -48,7 +48,8 @@ class Sugarcane extends Flowable{ return 0b1111; } - private function grow() : void{ + private function grow() : bool{ + $grew = false; for($y = 1; $y < 3; ++$y){ if(!$this->position->getWorld()->isInWorld($this->position->x, $this->position->y + $y, $this->position->z)){ break; @@ -61,12 +62,14 @@ class Sugarcane extends Flowable{ break; } $this->position->getWorld()->setBlock($b->position, $ev->getNewState()); + $grew = true; }else{ break; } } $this->age = 0; $this->position->getWorld()->setBlock($this->position, $this); + return $grew; } public function getAge() : int{ return $this->age; } @@ -82,12 +85,10 @@ class Sugarcane extends Flowable{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($item instanceof Fertilizer){ - if(!$this->getSide(Facing::DOWN)->isSameType($this)){ - $this->grow(); + if(!$this->getSide(Facing::DOWN)->isSameType($this) && $this->grow()){ + $item->pop(); } - $item->pop(); - return true; } diff --git a/src/block/SweetBerryBush.php b/src/block/SweetBerryBush.php index efb35845e..4412d0cff 100644 --- a/src/block/SweetBerryBush.php +++ b/src/block/SweetBerryBush.php @@ -99,9 +99,9 @@ class SweetBerryBush extends Flowable{ if(!$ev->isCancelled()){ $this->position->getWorld()->setBlock($this->position, $ev->getNewState()); + $item->pop(); } - $item->pop(); }elseif(($dropAmount = $this->getBerryDropAmount()) > 0){ $this->position->getWorld()->setBlock($this->position, $this->setAge(self::STAGE_BUSH_NO_BERRIES)); $this->position->getWorld()->dropItem($this->position, $this->asItem()->setCount($dropAmount));