From 6002057839160bc0bf73561ffcebb98f1d7e4626 Mon Sep 17 00:00:00 2001 From: Gustavo Ramos Rehermann Date: Thu, 17 Feb 2022 17:53:02 -0300 Subject: [PATCH] Stop creeper explosion sequence if target leaves line of sight --- .../attack_type_instructions.lua | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua index ac10194e5..736e2429e 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua @@ -26,6 +26,8 @@ local math_random = math.random |_| ]]-- +local minetest_line_of_sight = minetest.line_of_sight + mobs.explode_attack_walk = function(self,dtime) --this needs an exception @@ -36,17 +38,27 @@ mobs.explode_attack_walk = function(self,dtime) mobs.set_yaw_while_attacking(self) - local distance_from_attacking = vector_distance(self.object:get_pos(), self.attacking:get_pos()) + local pos = self.object:get_pos() + local attack_pos = self.attacking:get_pos() + local distance_from_attacking = vector_distance(pos, attack_pos) --make mob walk up to player within 2 nodes distance then start exploding - if distance_from_attacking >= self.reach and - --don't allow explosion to cancel unless out of the reach boundary - not (self.explosion_animation and self.explosion_animation > 0 and distance_from_attacking <= self.defuse_reach) then + if ( + distance_from_attacking >= self.reach and + --don't allow explosion to cancel unless out of the reach boundary + not (self.explosion_animation and self.explosion_animation > 0 and distance_from_attacking <= self.defuse_reach) or + --don't allow creeper to finish exploding animation if can't see target + not minetest_line_of_sight( + {x = pos.x, y = pos.y + self.eye_height, z = pos.z}, + {x = attack_pos.x, y = attack_pos.y + (self.attacking.eye_height or 0), z = attack_pos.z} + ) + ) then mobs.set_velocity(self, self.run_velocity) mobs.set_mob_animation(self,"run") mobs.reverse_explosion_animation(self,dtime) + else mobs.set_velocity(self,0) @@ -344,4 +356,4 @@ mobs.projectile_attack_fly = function(self, dtime) mobs.shoot_projectile(self) end end -end \ No newline at end of file +end