mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-19 15:35:52 +00:00
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:
parent
6f0eb019d2
commit
d834266635
@ -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());
|
||||
|
@ -69,7 +69,7 @@ abstract class Crops extends Flowable{
|
||||
$block->age = self::MAX_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());
|
||||
|
@ -51,7 +51,7 @@ class Sugarcane extends Flowable{
|
||||
return $bottom;
|
||||
}
|
||||
|
||||
private function grow(Position $pos) : bool{
|
||||
private function grow(Position $pos, ?Player $player = null) : bool{
|
||||
$grew = false;
|
||||
$world = $pos->getWorld();
|
||||
for($y = 1; $y < 3; ++$y){
|
||||
@ -60,7 +60,7 @@ class Sugarcane extends Flowable{
|
||||
}
|
||||
$b = $world->getBlockAt($pos->x, $pos->y + $y, $pos->z);
|
||||
if($b->getTypeId() === BlockTypeIds::AIR){
|
||||
$ev = new BlockGrowEvent($b, VanillaBlocks::SUGARCANE());
|
||||
$ev = new BlockGrowEvent($b, VanillaBlocks::SUGARCANE(), $player);
|
||||
$ev->call();
|
||||
if($ev->isCancelled()){
|
||||
break;
|
||||
@ -89,7 +89,7 @@ class Sugarcane extends Flowable{
|
||||
|
||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
|
||||
if($item instanceof Fertilizer){
|
||||
if($this->grow($this->seekToBottom())){
|
||||
if($this->grow($this->seekToBottom(), $player)){
|
||||
$item->pop();
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ class SweetBerryBush extends Flowable{
|
||||
$block = clone $this;
|
||||
$block->age++;
|
||||
|
||||
$ev = new BlockGrowEvent($this, $block);
|
||||
$ev = new BlockGrowEvent($this, $block, $player);
|
||||
$ev->call();
|
||||
|
||||
if(!$ev->isCancelled()){
|
||||
|
@ -23,9 +23,27 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\event\block;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\player\Player;
|
||||
|
||||
/**
|
||||
* Called when plants or crops grow.
|
||||
*/
|
||||
class BlockGrowEvent extends BaseBlockChangeEvent{
|
||||
|
||||
public function __construct(
|
||||
Block $block,
|
||||
Block $newState,
|
||||
private ?Player $player = null,
|
||||
){
|
||||
parent::__construct($block, $newState);
|
||||
}
|
||||
|
||||
/**
|
||||
* It returns the player which grows the crop.
|
||||
* It returns null when the crop grows by itself.
|
||||
*/
|
||||
public function getPlayer() : ?Player{
|
||||
return $this->player;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user