Implemented Farmland turns to dirt when jumped on. (#4434)

This commit is contained in:
Cosmic
2021-09-06 07:55:52 -04:00
committed by GitHub
parent 931c3ed77d
commit 710345d4b0
2 changed files with 63 additions and 0 deletions

View File

@ -24,9 +24,13 @@ declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\block\utils\BlockDataSerializer;
use pocketmine\entity\Entity;
use pocketmine\entity\Living;
use pocketmine\event\entity\EntityTrampleFarmlandEvent;
use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use function lcg_value;
class Farmland extends Transparent{
@ -86,6 +90,17 @@ class Farmland extends Transparent{
}
}
public function onEntityLand(Entity $entity) : ?float{
if($entity instanceof Living && lcg_value() < $entity->getFallDistance() - 0.5){
$ev = new EntityTrampleFarmlandEvent($entity, $this);
$ev->call();
if(!$ev->isCancelled()){
$this->getPosition()->getWorld()->setBlock($this->getPosition(), VanillaBlocks::DIRT());
}
}
return null;
}
protected function canHydrate() : bool{
//TODO: check rain
$start = $this->position->add(-4, 0, -4);