Cleaned up death animation handling, removed dead ticking from non-Living entities

This commit is contained in:
Dylan K. Taylor
2017-11-04 20:03:40 +00:00
parent 75e469c380
commit e9e22db1e7
3 changed files with 52 additions and 11 deletions

View File

@ -393,10 +393,6 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
/** @var bool */
public $onGround;
/** @var int */
public $deadTicks = 0;
/** @var int */
protected $maxDeadTicks = 0;
/** @var int */
protected $age = 0;
/** @var float */
@ -878,6 +874,16 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
$this->scheduleUpdate();
}
/**
* Called to tick entities while dead. Returns whether the entity should be flagged for despawn yet.
*
* @param int $tickDiff
* @return bool
*/
protected function onDeathUpdate(int $tickDiff) : bool{
return true;
}
public function isAlive() : bool{
return $this->health > 0;
}
@ -1267,13 +1273,10 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
}
if(!$this->isAlive()){
$this->deadTicks += $tickDiff;
if($this->deadTicks >= $this->maxDeadTicks){
$this->despawnFromAll();
if(!$this->isPlayer){
$this->flagForDespawn();
}
if($this->onDeathUpdate($tickDiff)){
$this->flagForDespawn();
}
return true;
}