Implement anvil fall damage (#5312)

This commit is contained in:
IvanCraft623
2023-03-27 14:17:08 -05:00
committed by GitHub
parent 04197d6b80
commit bea878e9e9
7 changed files with 76 additions and 2 deletions

View File

@ -30,8 +30,10 @@ use pocketmine\data\bedrock\block\BlockStateDeserializeException;
use pocketmine\data\SavedDataLoadingException;
use pocketmine\entity\Entity;
use pocketmine\entity\EntitySizeInfo;
use pocketmine\entity\Living;
use pocketmine\entity\Location;
use pocketmine\event\entity\EntityBlockChangeEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\ByteTag;
@ -44,6 +46,8 @@ use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
use pocketmine\world\format\io\GlobalBlockStateHandlers;
use pocketmine\world\sound\BlockBreakSound;
use function abs;
use function min;
use function round;
class FallingBlock extends Entity{
private const TAG_FALLING_BLOCK = "FallingBlock"; //TAG_Compound
@ -156,8 +160,20 @@ class FallingBlock extends Entity{
}
protected function onHitGround() : ?float{
if($this->block instanceof Fallable && !$this->block->onHitGround($this)){
$this->flagForDespawn();
if($this->block instanceof Fallable){
$damagePerBlock = $this->block->getFallDamagePerBlock();
if($damagePerBlock > 0 && ($fallenBlocks = round($this->fallDistance) - 1) > 0){
$damage = min($fallenBlocks * $damagePerBlock, $this->block->getMaxFallDamage());
foreach($this->getWorld()->getCollidingEntities($this->getBoundingBox()) as $entity){
if($entity instanceof Living){
$ev = new EntityDamageByEntityEvent($this, $entity, EntityDamageEvent::CAUSE_FALLING_BLOCK, $damage);
$entity->attack($ev);
}
}
}
if(!$this->block->onHitGround($this)){
$this->flagForDespawn();
}
}
return null;
}