mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-03 00:25:04 +00:00
Implemented Farmland turns to dirt when jumped on. (#4434)
This commit is contained in:
@ -24,9 +24,13 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\block;
|
namespace pocketmine\block;
|
||||||
|
|
||||||
use pocketmine\block\utils\BlockDataSerializer;
|
use pocketmine\block\utils\BlockDataSerializer;
|
||||||
|
use pocketmine\entity\Entity;
|
||||||
|
use pocketmine\entity\Living;
|
||||||
|
use pocketmine\event\entity\EntityTrampleFarmlandEvent;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
|
use function lcg_value;
|
||||||
|
|
||||||
class Farmland extends Transparent{
|
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{
|
protected function canHydrate() : bool{
|
||||||
//TODO: check rain
|
//TODO: check rain
|
||||||
$start = $this->position->add(-4, 0, -4);
|
$start = $this->position->add(-4, 0, -4);
|
||||||
|
48
src/event/entity/EntityTrampleFarmlandEvent.php
Normal file
48
src/event/entity/EntityTrampleFarmlandEvent.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\event\entity;
|
||||||
|
|
||||||
|
use pocketmine\block\Block;
|
||||||
|
use pocketmine\entity\Living;
|
||||||
|
use pocketmine\event\Cancellable;
|
||||||
|
use pocketmine\event\CancellableTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @phpstan-extends EntityEvent<Living>
|
||||||
|
*/
|
||||||
|
class EntityTrampleFarmlandEvent extends EntityEvent implements Cancellable{
|
||||||
|
use CancellableTrait;
|
||||||
|
|
||||||
|
/** @var Block */
|
||||||
|
private $block;
|
||||||
|
|
||||||
|
public function __construct(Living $entity, Block $block){
|
||||||
|
$this->entity = $entity;
|
||||||
|
$this->block = $block;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlock() : Block{
|
||||||
|
return $this->block;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user