From 658f244ae471ca248ff65973913650ab1a21c3e2 Mon Sep 17 00:00:00 2001 From: ancientmarinerdev Date: Mon, 19 Jun 2023 01:32:20 +0100 Subject: [PATCH] Creeper should not walk to player if it does not have line of sight. Mob shouldn't look at player it does not have line of sight to. --- mods/ENTITIES/mcl_mobs/combat.lua | 17 ++++++++++------- mods/ENTITIES/mcl_mobs/effects.lua | 10 ++++++++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/combat.lua b/mods/ENTITIES/mcl_mobs/combat.lua index 3b53e0d1a..836f53753 100644 --- a/mods/ENTITIES/mcl_mobs/combat.lua +++ b/mods/ENTITIES/mcl_mobs/combat.lua @@ -873,10 +873,13 @@ function mob_class:do_states_attack (dtime) local dist = vector.distance(p, s) if self.attack_type == "explode" then - local vec = { x = p.x - s.x, z = p.z - s.z } - yaw = (atan(vec.z / vec.x) +math.pi/ 2) - self.rotate - if p.x > s.x then yaw = yaw +math.pi end - yaw = self:set_yaw( yaw, 0, dtime) + + if target_line_of_sight then + local vec = { x = p.x - s.x, z = p.z - s.z } + yaw = (atan(vec.z / vec.x) +math.pi/ 2) - self.rotate + if p.x > s.x then yaw = yaw +math.pi end + yaw = self:set_yaw( yaw, 0, dtime) + end local node_break_radius = self.explosion_radius or 1 local entity_damage_radius = self.explosion_damage_radius @@ -900,10 +903,10 @@ function mob_class:do_states_attack (dtime) end -- walk right up to player unless the timer is active - if self.v_start and (self.stop_to_explode or dist < self.reach) then - self:set_velocity( 0) + if self.v_start and (self.stop_to_explode or dist < self.reach) or not target_line_of_sight then + self:set_velocity(0) else - self:set_velocity( self.run_velocity) + self:set_velocity(self.run_velocity) end if self.animation and self.animation.run_start then diff --git a/mods/ENTITIES/mcl_mobs/effects.lua b/mods/ENTITIES/mcl_mobs/effects.lua index 7953e6a47..aa44a67f7 100644 --- a/mods/ENTITIES/mcl_mobs/effects.lua +++ b/mods/ENTITIES/mcl_mobs/effects.lua @@ -316,8 +316,14 @@ local function who_are_you_looking_at (self, dtime) local stop_look_at_player = stop_look_at_player_chance == 1 - if self.attack or self.following then - self._locked_object = self.attack or self.following + if self.attack then + if not self.target_time_lost then + self._locked_object = self.attack + else + self._locked_object = nil + end + elseif self.following then + self._locked_object = self.following elseif self._locked_object then if stop_look_at_player then --minetest.log("Stop look: ".. self.name)