mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 10:53:05 +00:00
Refactor of health int -> float and fixed armor being useless when
computed damage reduction is less than 1
This commit is contained in:
@ -73,7 +73,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
$this->namedtag->Health = new FloatTag("Health", (float) $this->getMaxHealth());
|
||||
}
|
||||
|
||||
$this->setHealth($this->namedtag["Health"]);
|
||||
$this->setHealth((float) $this->namedtag["Health"]);
|
||||
|
||||
if(isset($this->namedtag->ActiveEffects)){
|
||||
foreach($this->namedtag->ActiveEffects->getValue() as $e){
|
||||
@ -100,10 +100,10 @@ abstract class Living extends Entity implements Damageable{
|
||||
$this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::ABSORPTION));
|
||||
}
|
||||
|
||||
public function setHealth($amount){
|
||||
public function setHealth(float $amount){
|
||||
$wasAlive = $this->isAlive();
|
||||
parent::setHealth($amount);
|
||||
$this->attributeMap->getAttribute(Attribute::HEALTH)->setValue($this->getHealth(), true);
|
||||
$this->attributeMap->getAttribute(Attribute::HEALTH)->setValue(ceil($this->getHealth()), true);
|
||||
if($this->isAlive() and !$wasAlive){
|
||||
$pk = new EntityEventPacket();
|
||||
$pk->entityRuntimeId = $this->getId();
|
||||
@ -112,11 +112,11 @@ abstract class Living extends Entity implements Damageable{
|
||||
}
|
||||
}
|
||||
|
||||
public function getMaxHealth(){
|
||||
return $this->attributeMap->getAttribute(Attribute::HEALTH)->getMaxValue();
|
||||
public function getMaxHealth() : int{
|
||||
return (int) $this->attributeMap->getAttribute(Attribute::HEALTH)->getMaxValue();
|
||||
}
|
||||
|
||||
public function setMaxHealth($amount){
|
||||
public function setMaxHealth(int $amount){
|
||||
$this->attributeMap->getAttribute(Attribute::HEALTH)->setMaxValue($amount);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user