changes to skeleton ai, theoretical performance increase with huge amount of mobs and players

This commit is contained in:
GameHerobrine 2024-04-12 06:06:59 +03:00
parent c9da91378d
commit da28b3b0ff
9 changed files with 89 additions and 96 deletions

View file

@ -5,19 +5,41 @@ abstract class Animal extends Creature implements Ageable, Breedable{
public $parent;
public $inLove; //do NOT add it into metadata, it doesnt send it to player
public $age;
public $loveTimeout;
public $closestPlayerThatCanFeedEID = false;
public $closestPlayerThatCanFeedDist = INF;
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data);
$this->setAge(isset($data["Age"]) ? $data["Age"] : 0);
if(isset($this->data["IsBaby"]) && $this->data["IsBaby"] && $this->getAge() >= 0){
$this->setAge(-24000);
}
$this->searchForClosestPlayers = true;
}
public function handlePrePlayerSearcher(){
parent::handlePrePlayerSearcher();
//$this->ai->addTask(new TaskTempt());
//$this->ai->addTask(new TaskPanic());
//$this->ai->addTask(new TaskMate());
if($this->closestPlayerThatCanFeedEID !== false && !isset($this->level->entityList[$this->closestPlayerThatCanFeedEID])){
$this->closestPlayerThatCanFeedEID = false;
$this->closestPlayerThatCanFeedDist = INF;
}
}
public function handlePlayerSearcher(Player $player, $dist){
parent::handlePlayerSearcher($player, $dist);
if($this->closestPlayerThatCanFeedDist >= $dist){
if($player->spawned && $this->isFood($player->getHeldItem()->id)){
$this->closestPlayerThatCanFeedDist = $dist;
$this->closestPlayerThatCanFeedEID = $player->entity->eid;
}
}
}
public function harm($dmg, $cause = "generic", $force = false){