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,11 +21,18 @@ abstract class Creature extends Living{
return parent::update($now);
}
public function handlePrePlayerSearcher(){
parent::handlePrePlayerSearcher();
if($this->closestPlayerEID !== false && !isset($this->level->entityList[$this->closestPlayerEID])){
$this->closestPlayerEID = false;
$this->closestPlayerDist = INF;
if($this->closestPlayerEID !== false){
$player = $this->level->entityList[$this->closestPlayerEID] ?? false;
if($player === false){
$this->closestPlayerEID = false;
$this->closestPlayerDist = 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->closestPlayerDist = $dist;
}
}
}