Player::teleport will set motion to 0, fixed possible divby0 when skeletonm shooting the player, fixed entities not untargetting dead players, fixed wrong distance calculations

This commit is contained in:
GameHerobrine 2024-07-12 17:50:06 +03:00
parent 2cd42fb605
commit 81aa575749
7 changed files with 84 additions and 30 deletions

View file

@ -21,21 +21,29 @@ abstract class Animal extends Creature implements Ageable, Breedable{
$this->searchForClosestPlayers = true;
}
public function isPlayerValid(Player $player){
return $player->spawned && $this->isFood($player->getHeldItem()->id) && !$player->entity->dead;
}
public function handlePrePlayerSearcher(){
parent::handlePrePlayerSearcher();
if($this->closestPlayerThatCanFeedEID !== false && !isset($this->level->entityList[$this->closestPlayerThatCanFeedEID])){
$this->closestPlayerThatCanFeedEID = false;
$this->closestPlayerThatCanFeedDist = INF;
if($this->closestPlayerThatCanFeedEID !== false){
$player = $this->level->entityList[$this->closestPlayerThatCanFeedEID] ?? false;
if($player === false || !$this->isPlayerValid($player->player)){
$this->closestPlayerThatCanFeedEID = false;
$this->closestPlayerThatCanFeedDist = INF;
}else{
$dist = ($this->x - $player->x)*($this->x - $player->x) + ($this->y - $player->y)*($this->y - $player->y) + ($this->z - $player->z)*($this->z - $player->z);
$this->closestPlayerThatCanFeedDist = $dist;
}
}
}
public function handlePlayerSearcher(Player $player, $dist){
parent::handlePlayerSearcher($player, $dist);
if($this->closestPlayerThatCanFeedDist >= $dist){
if($player->spawned && $this->isFood($player->getHeldItem()->id)){
if($this->isPlayerValid($player)){
$this->closestPlayerThatCanFeedDist = $dist;
$this->closestPlayerThatCanFeedEID = $player->entity->eid;
}