mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 20:19:44 +00:00
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:
parent
2cd42fb605
commit
81aa575749
7 changed files with 84 additions and 30 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue