more entity optimizations

This commit is contained in:
GameHerobrine 2023-07-28 02:50:23 +03:00
parent 2b0ad36e14
commit 2d9b37aa9c
12 changed files with 44 additions and 62 deletions

View file

@ -6,6 +6,7 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
public $target, $ai;
public $pathFinder, $path = null, $currentIndex = 0, $currentNode, $pathFollower;
public $ticksExisted = 0;
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
$this->target = false;
$this->ai = new EntityAI($this);
@ -15,7 +16,7 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
$this->canBeAttacked = true;
$this->hasGravity = true;
$this->hasKnockback = true;
if(self::$despawnMobs) $this->server->schedule(self::$despawnTimer, [$this, "close"]); //900*20
//if(self::$despawnMobs) $this->server->schedule(self::$despawnTimer, [$this, "close"]); //900*20
}
public function fall(){
$dmg = floor($this->fallDistance - 3);
@ -62,6 +63,9 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
}
public function update(){
if(self::$despawnMobs && ++$this->ticksExisted > self::$despawnTimer){
$this->close();
}
if(!$this->dead && Entity::$allowedAI && $this->idleTime <= 0) {
$this->ai->updateTasks();
}