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: MineClone2/MineClone2#4064
Co-authored-by: the-real-herowl <wiktor_t-i@proton.me>
Co-committed-by: the-real-herowl <wiktor_t-i@proton.me>
This commit is contained in:
the-real-herowl 2023-12-10 16:10:33 +00:00 committed by the-real-herowl
parent d4797e13af
commit cf70de0ecc
2 changed files with 6 additions and 1 deletions

View File

@ -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

View File

@ -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,