mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 02:42:58 +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:
@ -300,8 +300,8 @@ abstract class Entity extends Location implements Metadatable{
|
||||
/** @var float */
|
||||
protected $baseOffset = 0.0;
|
||||
|
||||
/** @var int */
|
||||
private $health = 20;
|
||||
/** @var float */
|
||||
private $health = 20.0;
|
||||
private $maxHealth = 20;
|
||||
|
||||
/** @var float */
|
||||
@ -921,9 +921,9 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @return float
|
||||
*/
|
||||
public function getHealth(){
|
||||
public function getHealth() : float{
|
||||
return $this->health;
|
||||
}
|
||||
|
||||
@ -934,11 +934,10 @@ abstract class Entity extends Location implements Metadatable{
|
||||
/**
|
||||
* Sets the health of the Entity. This won't send any update to the players
|
||||
*
|
||||
* @param int $amount
|
||||
* @param float $amount
|
||||
*/
|
||||
public function setHealth($amount){
|
||||
$amount = (int) $amount;
|
||||
if($amount === $this->health){
|
||||
public function setHealth(float $amount){
|
||||
if($amount == $this->health){
|
||||
return;
|
||||
}
|
||||
|
||||
@ -947,7 +946,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$this->kill();
|
||||
}
|
||||
}elseif($amount <= $this->getMaxHealth() or $amount < $this->health){
|
||||
$this->health = (int) $amount;
|
||||
$this->health = $amount;
|
||||
}else{
|
||||
$this->health = $this->getMaxHealth();
|
||||
}
|
||||
@ -982,15 +981,15 @@ abstract class Entity extends Location implements Metadatable{
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxHealth(){
|
||||
public function getMaxHealth() : int{
|
||||
return $this->maxHealth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $amount
|
||||
*/
|
||||
public function setMaxHealth($amount){
|
||||
$this->maxHealth = (int) $amount;
|
||||
public function setMaxHealth(int $amount){
|
||||
$this->maxHealth = $amount;
|
||||
}
|
||||
|
||||
public function canCollideWith(Entity $entity) : bool{
|
||||
|
Reference in New Issue
Block a user