From 0a8fff65249610aba7fef7e9675bf28469265f29 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Thu, 22 Apr 2021 22:08:54 -0400 Subject: [PATCH] Add in mob criticals when falling --- mods/ENTITIES/mcl_mobs/api/api.lua | 1 + .../api/mob_functions/death_logic.lua | 34 +---------- .../api/mob_functions/interaction.lua | 8 +++ .../api/mob_functions/mob_effects.lua | 61 +++++++++++++++++++ 4 files changed, 71 insertions(+), 33 deletions(-) create mode 100644 mods/ENTITIES/mcl_mobs/api/mob_functions/mob_effects.lua diff --git a/mods/ENTITIES/mcl_mobs/api/api.lua b/mods/ENTITIES/mcl_mobs/api/api.lua index e5e9d32f48..98bb443c5c 100644 --- a/mods/ENTITIES/mcl_mobs/api/api.lua +++ b/mods/ENTITIES/mcl_mobs/api/api.lua @@ -160,6 +160,7 @@ dofile(api_path .. "set_up.lua") dofile(api_path .. "attack_type_instructions.lua") dofile(api_path .. "sound_handling.lua") dofile(api_path .. "death_logic.lua") +dofile(api_path .. "mob_effects.lua") mobs.spawning_mobs = {} diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/death_logic.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/death_logic.lua index 53d517a584..1666993585 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/death_logic.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/death_logic.lua @@ -1,5 +1,4 @@ local minetest_add_item = minetest.add_item -local minetest_add_particlespawner = minetest.add_particlespawner local minetest_sound_play = minetest.sound_play local math_pi = math.pi @@ -10,37 +9,6 @@ local HALF_PI = math_pi / 2 local vector_new = vector.new -local death_effect = function(self) - - local pos = self.object:get_pos() - local yaw = self.object:get_yaw() - local collisionbox = self.object:get_properties().collisionbox - - local min, max - - if collisionbox then - min = {x=collisionbox[1], y=collisionbox[2], z=collisionbox[3]} - max = {x=collisionbox[4], y=collisionbox[5], z=collisionbox[6]} - end - - minetest_add_particlespawner({ - amount = 50, - time = 0.001, - minpos = vector.add(pos, min), - maxpos = vector.add(pos, max), - minvel = vector.new(-0.5,0.5,-0.5), - maxvel = vector.new(0.5,1,0.5), - minexptime = 1.1, - maxexptime = 1.5, - minsize = 1, - maxsize = 2, - collisiondetection = false, - vertical = false, - texture = "mcl_particles_mob_death.png", -- this particle looks strange - }) -end - - -- drop items local item_drop = function(self, cooked, looting_level) @@ -127,7 +95,7 @@ mobs.death_logic = function(self, dtime) item_drop(self,false,1) - death_effect(self) + mobs.death_effect(self) self.object:remove() diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua index 32011aafe8..f43075b4e0 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua @@ -170,6 +170,14 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir) end end + + --if player is falling multiply damage by 1.5 + --critical hit + if hitter:get_velocity().y < 0 then + damage = damage * 1.5 + mobs.critical_effect(self) + end + local die = false -- only play hit sound and show blood effects if damage is 1 or over; lower to 0.1 to ensure armor works appropriately. diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/mob_effects.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/mob_effects.lua new file mode 100644 index 0000000000..1bf79f8aab --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/mob_effects.lua @@ -0,0 +1,61 @@ +local minetest_add_particlespawner = minetest.add_particlespawner + +mobs.death_effect = function(self) + + local pos = self.object:get_pos() + local yaw = self.object:get_yaw() + local collisionbox = self.object:get_properties().collisionbox + + local min, max + + if collisionbox then + min = {x=collisionbox[1], y=collisionbox[2], z=collisionbox[3]} + max = {x=collisionbox[4], y=collisionbox[5], z=collisionbox[6]} + end + + minetest_add_particlespawner({ + amount = 50, + time = 0.0001, + minpos = vector.add(pos, min), + maxpos = vector.add(pos, max), + minvel = vector.new(-0.5,0.5,-0.5), + maxvel = vector.new(0.5,1,0.5), + minexptime = 1.1, + maxexptime = 1.5, + minsize = 1, + maxsize = 2, + collisiondetection = false, + vertical = false, + texture = "mcl_particles_mob_death.png", -- this particle looks strange + }) +end + +mobs.critical_effect = function(self) + + local pos = self.object:get_pos() + local yaw = self.object:get_yaw() + local collisionbox = self.object:get_properties().collisionbox + + local min, max + + if collisionbox then + min = {x=collisionbox[1], y=collisionbox[2], z=collisionbox[3]} + max = {x=collisionbox[4], y=collisionbox[5], z=collisionbox[6]} + end + + minetest_add_particlespawner({ + amount = 10, + time = 0.0001, + minpos = vector.add(pos, min), + maxpos = vector.add(pos, max), + minvel = vector.new(-1,1,-1), + maxvel = vector.new(1,3,1), + minexptime = 0.7, + maxexptime = 1, + minsize = 1, + maxsize = 2, + collisiondetection = false, + vertical = false, + texture = "heart.png^[colorize:black:255", + }) +end \ No newline at end of file