Implemented Absorption effect

This is a little buggy due to a client-sided bug. https://bugs.mojang.com/browse/MCPE-20520
TODO: add attribute save/restore
This commit is contained in:
Dylan K. Taylor
2017-03-21 13:23:57 +00:00
parent c21768df26
commit 940b20c191
3 changed files with 46 additions and 1 deletions

View File

@ -735,7 +735,21 @@ abstract class Entity extends Location implements Metadatable{
$this->setLastDamageCause($source);
$this->setHealth($this->getHealth() - $source->getFinalDamage());
$damage = $source->getFinalDamage();
$absorption = $this->getAbsorption();
if($absorption > 0){
if($absorption > $damage){
//Use absorption health before normal health.
$this->setAbsorption($absorption - $damage);
$damage = 0;
}else{
$this->setAbsorption(0);
$damage -= $absorption;
}
}
$this->setHealth($this->getHealth() - $damage);
}
/**
@ -785,6 +799,14 @@ abstract class Entity extends Location implements Metadatable{
}
}
public function getAbsorption() : int{
return 0;
}
public function setAbsorption(int $absorption){
}
/**
* @param EntityDamageEvent $type
*/