From bf367fffd054fe180dbc6d7f46e20e286d68bb09 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Tue, 20 Apr 2021 21:34:18 -0400 Subject: [PATCH] Add in sound_handling and make explosion type mobs make their attack sound before explosion animation --- mods/ENTITIES/mcl_mobs/api/api.lua | 1 + .../attack_type_instructions.lua | 9 ++++-- .../api/mob_functions/sound_handling.lua | 32 +++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 mods/ENTITIES/mcl_mobs/api/mob_functions/sound_handling.lua diff --git a/mods/ENTITIES/mcl_mobs/api/api.lua b/mods/ENTITIES/mcl_mobs/api/api.lua index 5734ee1c7..e10243098 100644 --- a/mods/ENTITIES/mcl_mobs/api/api.lua +++ b/mods/ENTITIES/mcl_mobs/api/api.lua @@ -157,6 +157,7 @@ dofile(api_path .. "interaction.lua") dofile(api_path .. "movement.lua") dofile(api_path .. "set_up.lua") dofile(api_path .. "attack_type_instructions.lua") +dofile(api_path .. "sound_handling.lua") mobs.spawning_mobs = {} 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 e0e16691d..1b8928839 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 @@ -14,8 +14,6 @@ mobs.explode_attack_walk = function(self,dtime) mobs.set_yaw_while_attacking(self) --make mob walk up to player within 2 nodes distance then start exploding - - --THIS NEEDS TO BE RECODED TO TAKE COLLISION BOXES INTO ACCOUNT!!! if vector_distance(self.object:get_pos(), self.attacking:get_pos()) >= self.reach then mobs.set_velocity(self, self.run_velocity) mobs.set_mob_animation(self,"run") @@ -28,12 +26,17 @@ mobs.explode_attack_walk = function(self,dtime) if not self.explosion_animation then self.explosion_animation = 0 end + + --play ignite sound + if self.explosion_animation == 0 then + mobs.play_sound(self,"attack") + end + mobs.set_mob_animation(self,"stand") mobs.handle_explosion_animation(self) self.explosion_animation = self.explosion_animation + (dtime/2) - end --make explosive mobs jump diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/sound_handling.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/sound_handling.lua new file mode 100644 index 000000000..e699a1f29 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/sound_handling.lua @@ -0,0 +1,32 @@ +local math_random = math.random + + +--generic call for sound handler for mobs (data access) +mobs.play_sound = function(self,sound) + local soundinfo = self.sounds + + if not soundinfo then + return + end + + local play_sound = soundinfo[sound] + + if not play_sound then + return + end + + mobs.play_sound_handler(self, play_sound) +end + + +--generic sound handler for mobs +mobs.play_sound_handler = function(self, sound) + local pitch = (100 + math_random(-15,15) + math_random()) / 100 + + minetest.sound_play(sound, { + object = self.object, + gain = 1.0, + max_hear_distance = self.sounds.distance, + pitch = pitch, + }, true) +end \ No newline at end of file