BlockGrowEvent: add player information for bonemeal usage (#5596)

this is in line with StructureGrowEvent, which also has a similar API.
This commit is contained in:
Hugo_
2023-05-08 18:38:07 +02:00
committed by GitHub
parent 6f0eb019d2
commit d834266635
5 changed files with 26 additions and 8 deletions

View File

@ -94,7 +94,7 @@ class CocoaBlock extends Transparent{
}
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
if($item instanceof Fertilizer && $this->grow()){
if($item instanceof Fertilizer && $this->grow($player)){
$item->pop();
return true;
@ -119,11 +119,11 @@ class CocoaBlock extends Transparent{
}
}
private function grow() : bool{
private function grow(?Player $player = null) : bool{
if($this->age < self::MAX_AGE){
$block = clone $this;
$block->age++;
$ev = new BlockGrowEvent($this, $block);
$ev = new BlockGrowEvent($this, $block, $player);
$ev->call();
if(!$ev->isCancelled()){
$this->position->getWorld()->setBlock($this->position, $ev->getNewState());