Save and restore entity health

This commit is contained in:
Shoghi Cervantes 2014-07-09 20:23:58 +02:00
parent 981796fd4c
commit 1f882f42d3

View File

@ -27,6 +27,7 @@ use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityDeathEvent;
use pocketmine\event\entity\EntityRegainHealthEvent;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\Short;
use pocketmine\network\protocol\EntityEventPacket;
use pocketmine\Server;
use pocketmine\item\Item;
@ -37,7 +38,21 @@ abstract class Living extends Entity implements Damageable{
protected $drag = 0.02;
protected function initEntity(){
if(isset($this->namedtag->HealF)){
$this->namedtag->Health = new Short("Health", (int) $this->namedtag["HealF"]);
unset($this->namedtag->HealF);
}
if(!isset($this->namedtag->Health) or !($this->namedtag->Health instanceof Short)){
$this->namedtag->Health = new Short("Health", $this->getMaxHealth());
}
$this->setHealth($this->namedtag["Health"]);
}
public function saveNBT(){
parent::saveNBT();
$this->namedtag->Health = new Short("Health", $this->getHealth());
}
public abstract function getName();