mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-15 02:09:42 +00:00
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:
parent
c21768df26
commit
940b20c191
@ -427,6 +427,7 @@ class Effect{
|
||||
$speed *= (1 - 0.15 * $this->amplifier);
|
||||
$attr->setValue($speed, true);
|
||||
break;
|
||||
|
||||
case Effect::HEALTH_BOOST:
|
||||
$attr = $entity->getAttributeMap()->getAttribute(Attribute::HEALTH);
|
||||
if($ev->willModify() and $oldEffect !== null){
|
||||
@ -438,6 +439,17 @@ class Effect{
|
||||
$max += (4 * ($this->amplifier + 1));
|
||||
$attr->setMaxValue($max);
|
||||
break;
|
||||
case Effect::ABSORPTION:
|
||||
if($ev->willModify() and $oldEffect !== null){
|
||||
$value = $entity->getAbsorption() - (4 * ($oldEffect->getAmplifier() + 1));
|
||||
}else{
|
||||
$value = $entity->getAbsorption();
|
||||
}
|
||||
|
||||
$value += (4 * ($this->amplifier + 1));
|
||||
$entity->setAbsorption($value);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -477,6 +489,9 @@ class Effect{
|
||||
$attr = $entity->getAttributeMap()->getAttribute(Attribute::HEALTH);
|
||||
$attr->setMaxValue($attr->getMaxValue() - (4 * ($this->amplifier + 1)));
|
||||
break;
|
||||
case Effect::ABSORPTION:
|
||||
$entity->setAbsorption($entity->getAbsorption() - (4 * ($this->amplifier + 1)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -85,6 +85,14 @@ abstract class Living extends Entity implements Damageable{
|
||||
$this->attributeMap->getAttribute(Attribute::HEALTH)->setMaxValue($amount);
|
||||
}
|
||||
|
||||
public function getAbsorption() : int{
|
||||
return (int) $this->attributeMap->getAttribute(Attribute::ABSORPTION)->getValue();
|
||||
}
|
||||
|
||||
public function setAbsorption(int $absorption){
|
||||
$this->attributeMap->getAttribute(Attribute::ABSORPTION)->setValue($absorption);
|
||||
}
|
||||
|
||||
public function saveNBT(){
|
||||
parent::saveNBT();
|
||||
$this->namedtag->Health = new ShortTag("Health", $this->getHealth());
|
||||
|
Loading…
x
Reference in New Issue
Block a user