mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-23 19:34:15 +00:00
Bonemeal is no longer consumed when cancelling plant growth events (#4551)
This commit is contained in:
parent
0989c77037
commit
07b1cff306
@ -80,10 +80,9 @@ abstract class Crops extends Flowable{
|
|||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$this->position->getWorld()->setBlock($this->position, $ev->getNewState());
|
$this->position->getWorld()->setBlock($this->position, $ev->getNewState());
|
||||||
|
$item->pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
$item->pop();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,9 +76,7 @@ class Sapling extends Flowable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($item instanceof Fertilizer){
|
if($item instanceof Fertilizer && $this->grow($player)){
|
||||||
$this->grow($player);
|
|
||||||
|
|
||||||
$item->pop();
|
$item->pop();
|
||||||
|
|
||||||
return true;
|
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());
|
$random = new Random(mt_rand());
|
||||||
$tree = TreeFactory::get($random, $this->treeType);
|
$tree = TreeFactory::get($random, $this->treeType);
|
||||||
$transaction = $tree?->getBlockTransaction($this->position->getWorld(), $this->position->getFloorX(), $this->position->getFloorY(), $this->position->getFloorZ(), $random);
|
$transaction = $tree?->getBlockTransaction($this->position->getWorld(), $this->position->getFloorX(), $this->position->getFloorY(), $this->position->getFloorZ(), $random);
|
||||||
if($transaction === null){
|
if($transaction === null){
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ev = new StructureGrowEvent($this, $transaction, $player);
|
$ev = new StructureGrowEvent($this, $transaction, $player);
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$transaction->apply();
|
return $transaction->apply();
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFuelTime() : int{
|
public function getFuelTime() : int{
|
||||||
|
@ -48,7 +48,8 @@ class Sugarcane extends Flowable{
|
|||||||
return 0b1111;
|
return 0b1111;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function grow() : void{
|
private function grow() : bool{
|
||||||
|
$grew = false;
|
||||||
for($y = 1; $y < 3; ++$y){
|
for($y = 1; $y < 3; ++$y){
|
||||||
if(!$this->position->getWorld()->isInWorld($this->position->x, $this->position->y + $y, $this->position->z)){
|
if(!$this->position->getWorld()->isInWorld($this->position->x, $this->position->y + $y, $this->position->z)){
|
||||||
break;
|
break;
|
||||||
@ -61,12 +62,14 @@ class Sugarcane extends Flowable{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$this->position->getWorld()->setBlock($b->position, $ev->getNewState());
|
$this->position->getWorld()->setBlock($b->position, $ev->getNewState());
|
||||||
|
$grew = true;
|
||||||
}else{
|
}else{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->age = 0;
|
$this->age = 0;
|
||||||
$this->position->getWorld()->setBlock($this->position, $this);
|
$this->position->getWorld()->setBlock($this->position, $this);
|
||||||
|
return $grew;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAge() : int{ return $this->age; }
|
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{
|
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
|
||||||
if($item instanceof Fertilizer){
|
if($item instanceof Fertilizer){
|
||||||
if(!$this->getSide(Facing::DOWN)->isSameType($this)){
|
if(!$this->getSide(Facing::DOWN)->isSameType($this) && $this->grow()){
|
||||||
$this->grow();
|
$item->pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
$item->pop();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,9 +99,9 @@ class SweetBerryBush extends Flowable{
|
|||||||
|
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$this->position->getWorld()->setBlock($this->position, $ev->getNewState());
|
$this->position->getWorld()->setBlock($this->position, $ev->getNewState());
|
||||||
|
$item->pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
$item->pop();
|
|
||||||
}elseif(($dropAmount = $this->getBerryDropAmount()) > 0){
|
}elseif(($dropAmount = $this->getBerryDropAmount()) > 0){
|
||||||
$this->position->getWorld()->setBlock($this->position, $this->setAge(self::STAGE_BUSH_NO_BERRIES));
|
$this->position->getWorld()->setBlock($this->position, $this->setAge(self::STAGE_BUSH_NO_BERRIES));
|
||||||
$this->position->getWorld()->dropItem($this->position, $this->asItem()->setCount($dropAmount));
|
$this->position->getWorld()->dropItem($this->position, $this->asItem()->setCount($dropAmount));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user