mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Implement anvil damage on fall (#5345)
This commit is contained in:
parent
8e600b4a78
commit
84f9136b95
@ -30,12 +30,15 @@ use pocketmine\block\utils\HorizontalFacingTrait;
|
||||
use pocketmine\block\utils\SupportType;
|
||||
use pocketmine\data\runtime\RuntimeDataReader;
|
||||
use pocketmine\data\runtime\RuntimeDataWriter;
|
||||
use pocketmine\entity\object\FallingBlock;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\math\AxisAlignedBB;
|
||||
use pocketmine\math\Facing;
|
||||
use pocketmine\math\Vector3;
|
||||
use pocketmine\player\Player;
|
||||
use pocketmine\world\BlockTransaction;
|
||||
use function lcg_value;
|
||||
use function round;
|
||||
|
||||
class Anvil extends Transparent implements Fallable{
|
||||
use FallableTrait;
|
||||
@ -95,4 +98,15 @@ class Anvil extends Transparent implements Fallable{
|
||||
}
|
||||
return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
|
||||
}
|
||||
|
||||
public function onHitGround(FallingBlock $blockEntity) : bool{
|
||||
if(lcg_value() < 0.05 + (round($blockEntity->getFallDistance()) - 1) * 0.05){
|
||||
if($this->damage !== self::VERY_DAMAGED){
|
||||
$this->damage = $this->damage + 1;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\block\utils;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\entity\object\FallingBlock;
|
||||
|
||||
interface Fallable{
|
||||
|
||||
@ -33,4 +34,10 @@ interface Fallable{
|
||||
* Return null if you don't want to change the usual behaviour.
|
||||
*/
|
||||
public function tickFalling() : ?Block;
|
||||
|
||||
/**
|
||||
* Called when FallingBlock hits the ground.
|
||||
* Returns whether the block should be placed.
|
||||
*/
|
||||
public function onHitGround(FallingBlock $blockEntity) : bool;
|
||||
}
|
||||
|
@ -58,4 +58,8 @@ trait FallableTrait{
|
||||
public function tickFalling() : ?Block{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function onHitGround(FallingBlock $blockEntity) : bool{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -145,6 +145,13 @@ class FallingBlock extends Entity{
|
||||
return $hasUpdate;
|
||||
}
|
||||
|
||||
protected function onHitGround() : ?float{
|
||||
if($this->block instanceof Fallable && !$this->block->onHitGround($this)){
|
||||
$this->flagForDespawn();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getBlock() : Block{
|
||||
return $this->block;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user