mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-09 11:16:57 +00:00
Implement anvil fall damage (#5312)
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user