Bonemeal is no longer consumed when cancelling plant growth events (#4551)

This commit is contained in:
Colin
2021-11-05 17:15:55 +01:00
committed by GitHub
parent 0989c77037
commit 07b1cff306
4 changed files with 13 additions and 14 deletions

View File

@ -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{