mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-19 04:15:04 +00:00
Added /kill, base entity health methods
This commit is contained in:
@@ -92,6 +92,10 @@ abstract class Entity extends Position{
|
||||
public $width;
|
||||
public $length;
|
||||
|
||||
/** @var int */
|
||||
private $health = 20;
|
||||
private $maxHealth = 20;
|
||||
|
||||
public $fallDistance;
|
||||
public $ticksLived;
|
||||
public $lastUpdate;
|
||||
@@ -184,6 +188,44 @@ abstract class Entity extends Position{
|
||||
|
||||
abstract function heal($amount, $source = "generic");
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getHealth(){
|
||||
return $this->health;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the health of the Entity. This won't send any update to the players
|
||||
*
|
||||
* @param int $amount
|
||||
*/
|
||||
public function setHealth($amount){
|
||||
if($amount < 0){
|
||||
$this->health = 0;
|
||||
$this->dead = true;
|
||||
}elseif($amount > $this->getMaxHealth()){
|
||||
$this->health = $this->getMaxHealth();
|
||||
}else{
|
||||
$this->health = (int) $amount;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxHealth(){
|
||||
return $this->maxHealth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $amount
|
||||
*/
|
||||
public function setMaxHealth($amount){
|
||||
$this->maxHealth = (int) $amount;
|
||||
$this->health = (int) min($this->health, $this->maxHealth);
|
||||
}
|
||||
|
||||
public function onUpdate(){
|
||||
if($this->closed !== false){
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user