From 7b39170839d6527571849c34a245ff7427f85d10 Mon Sep 17 00:00:00 2001 From: nixnoxus Date: Sun, 3 Mar 2024 11:29:44 +0100 Subject: [PATCH] add mob_class:shoot_reach --- mods/ENTITIES/mcl_mobs/api.txt | 1 + mods/ENTITIES/mcl_mobs/combat.lua | 4 ++-- mods/ENTITIES/mcl_mobs/init.lua | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.txt b/mods/ENTITIES/mcl_mobs/api.txt index fe0da4be2..ebf69181e 100644 --- a/mods/ENTITIES/mcl_mobs/api.txt +++ b/mods/ENTITIES/mcl_mobs/api.txt @@ -82,6 +82,7 @@ functions needed for the mob to work properly which contains the following: 'reach' is how far the mob can attack player when standing nearby, default is 3 nodes. + 'shoot_reach' is how far the mob can shoot, default is 16 nodes. 'docile_by_day' when true has mobs wandering around during daylight hours and only attacking player at night or when provoked. diff --git a/mods/ENTITIES/mcl_mobs/combat.lua b/mods/ENTITIES/mcl_mobs/combat.lua index 3b28c1a37..87a6b4228 100644 --- a/mods/ENTITIES/mcl_mobs/combat.lua +++ b/mods/ENTITIES/mcl_mobs/combat.lua @@ -1154,9 +1154,9 @@ function mob_class:do_states_attack (dtime) end end - elseif self.attack_type == "shoot" + elseif dist <= self.shoot_reach and (self.attack_type == "shoot" or (self.attack_type == "dogshoot" and self:dogswitch(dtime) == 1) - or (self.attack_type == "dogshoot" and (dist > self.reach or dist < self.avoid_distance and self.shooter_avoid_enemy) and self:dogswitch() == 0) then + or (self.attack_type == "dogshoot" and (dist > self.reach or dist < self.avoid_distance and self.shooter_avoid_enemy) and self:dogswitch() == 0)) then p.y = p.y - .5 s.y = s.y + .5 diff --git a/mods/ENTITIES/mcl_mobs/init.lua b/mods/ENTITIES/mcl_mobs/init.lua index fb39fa151..fbf18dd25 100644 --- a/mods/ENTITIES/mcl_mobs/init.lua +++ b/mods/ENTITIES/mcl_mobs/init.lua @@ -229,6 +229,7 @@ function mcl_mobs.register_mob(name, def) health = 0, frame_speed_multiplier = 1, reach = def.reach or 3, + shoot_reach = def.shoot_reach or def.view_range or 16, htimer = 0, texture_list = def.textures, child_texture = def.child_texture,