From cf70de0ecc944f4ca797a3d1091e2b5ed04aa366 Mon Sep 17 00:00:00 2001 From: the-real-herowl Date: Sun, 10 Dec 2023 16:10:33 +0000 Subject: [PATCH] Add an on_attack callback for mobs (#4064) Added an on_attack callback that allows to execute additional custom logic after each attack. Reviewed-on: https://git.minetest.land/MineClone2/MineClone2/pulls/4064 Co-authored-by: the-real-herowl Co-committed-by: the-real-herowl --- mods/ENTITIES/mcl_mobs/combat.lua | 4 ++++ mods/ENTITIES/mcl_mobs/init.lua | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_mobs/combat.lua b/mods/ENTITIES/mcl_mobs/combat.lua index 6b660c787..bb16eb71e 100644 --- a/mods/ENTITIES/mcl_mobs/combat.lua +++ b/mods/ENTITIES/mcl_mobs/combat.lua @@ -1252,5 +1252,9 @@ function mob_class:do_states_attack (dtime) self.attack_state(self, dtime) else + if self.on_attack then + self.on_attack(self, dtime) + end + end end diff --git a/mods/ENTITIES/mcl_mobs/init.lua b/mods/ENTITIES/mcl_mobs/init.lua index 630548f12..b0fc73d6e 100644 --- a/mods/ENTITIES/mcl_mobs/init.lua +++ b/mods/ENTITIES/mcl_mobs/init.lua @@ -314,7 +314,8 @@ function mcl_mobs.register_mob(name, def) return self:mob_activate(staticdata, def, dtime) end, - attack_state = def.attack_state, + attack_state = def.attack_state, -- custom attack state + on_attack = def.on_attack, -- called after attack, useful with otherwise predefined attack states (not custom) harmed_by_heal = def.harmed_by_heal, is_boss = def.is_boss, dealt_effect = def.dealt_effect,