From 75844b5a62a0d4ee4ea8a65cf82f59bdf0c02b9b Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Wed, 14 Feb 2024 05:49:06 +0300 Subject: [PATCH] fixed target invalidation --- src/Player.php | 1 + src/entity/Entity.php | 2 +- src/entity/ai/tasks/TaskAttackPlayer.php | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Player.php b/src/Player.php index 2007b54a..84b00523 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1313,6 +1313,7 @@ class Player{ $this->chunkCount = []; $this->cratingItems = []; $this->received = []; + $this->entity->close(); } } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index abc1d488..be9a3016 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -1399,7 +1399,7 @@ class Entity extends Position if($health < $this->health){ $harm = true; $dmg = $this->health - $health; - if(($this->class !== ENTITY_PLAYER or (($this->player instanceof Player) and (($this->player->gamemode & 0x01) === 0x00 or $force === true))) and ($this->dmgcounter[0] < microtime(true) or $this->dmgcounter[1] < $dmg) and ! $this->dead){ + if(($this->class !== ENTITY_PLAYER or (($this->player instanceof Player) and (($this->player->gamemode & 0x01) === 0x00 or $force === true))) and ($this->dmgcounter[0] < microtime(true) or $this->dmgcounter[1] < $dmg) and !$this->dead){ $this->dmgcounter[0] = microtime(true) + 0.5; $this->dmgcounter[1] = $dmg; } else{ diff --git a/src/entity/ai/tasks/TaskAttackPlayer.php b/src/entity/ai/tasks/TaskAttackPlayer.php index 9253bd57..eba7d316 100644 --- a/src/entity/ai/tasks/TaskAttackPlayer.php +++ b/src/entity/ai/tasks/TaskAttackPlayer.php @@ -50,8 +50,8 @@ class TaskAttackPlayer extends TaskBase public function isTargetValid(EntityAI $ai){ - $e = $ai->entity; //TODO sometimes it keeps being valid even after getting invalid (/gm 1 -> /gm 0 switch) - if($e->target instanceof Entity){ + $e = $ai->entity; + if($e->target instanceof Entity && !$e->target->closed){ $t = $e->target; $xDiff = ($t->x - $e->x); $yDiff = ($t->y - $e->y);