StructureGrowEvent: added API to get the player who caused the growth (#4445)

This commit is contained in:
Matt
2021-10-09 23:51:46 +02:00
committed by GitHub
parent ccc881ee58
commit 09715906c8
4 changed files with 25 additions and 14 deletions

View File

@ -77,7 +77,7 @@ class Sapling extends Flowable{
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
if($item instanceof Fertilizer){
$this->grow();
$this->grow($player);
$item->pop();
@ -100,7 +100,7 @@ class Sapling extends Flowable{
public function onRandomTick() : void{
if($this->position->getWorld()->getFullLightAt($this->position->getFloorX(), $this->position->getFloorY(), $this->position->getFloorZ()) >= 8 and mt_rand(1, 7) === 1){
if($this->ready){
$this->grow();
$this->grow(null);
}else{
$this->ready = true;
$this->position->getWorld()->setBlock($this->position, $this);
@ -108,7 +108,7 @@ class Sapling extends Flowable{
}
}
private function grow() : void{
private function grow(?Player $player) : void{
$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);
@ -116,7 +116,7 @@ class Sapling extends Flowable{
return;
}
$ev = new StructureGrowEvent($this, $transaction);
$ev = new StructureGrowEvent($this, $transaction, $player);
$ev->call();
if($ev->isCancelled()){
return;