From d9424ad82e6fc6ddcd9601dab230fe421f535633 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Thu, 3 Oct 2019 11:53:26 +0200 Subject: [PATCH] Make dmg particles proportional to dmg --- mods/ENTITIES/mcl_mobs/api.lua | 70 +++++++++++++++-------- mods/ENTITIES/mcl_mobs/api.txt | 2 - mods/ENTITIES/mobs_mc/blaze.lua | 1 - mods/ENTITIES/mobs_mc/creeper.lua | 1 - mods/ENTITIES/mobs_mc/ender_dragon.lua | 1 - mods/ENTITIES/mobs_mc/enderman.lua | 1 - mods/ENTITIES/mobs_mc/endermite.lua | 1 - mods/ENTITIES/mobs_mc/ghast.lua | 1 - mods/ENTITIES/mobs_mc/guardian.lua | 1 - mods/ENTITIES/mobs_mc/guardian_elder.lua | 1 - mods/ENTITIES/mobs_mc/horse.lua | 1 - mods/ENTITIES/mobs_mc/iron_golem.lua | 1 - mods/ENTITIES/mobs_mc/shulker.lua | 1 - mods/ENTITIES/mobs_mc/silverfish.lua | 1 - mods/ENTITIES/mobs_mc/skeleton+stray.lua | 1 - mods/ENTITIES/mobs_mc/skeleton_wither.lua | 1 - mods/ENTITIES/mobs_mc/snowman.lua | 1 - mods/ENTITIES/mobs_mc/spider.lua | 1 - mods/ENTITIES/mobs_mc/wither.lua | 1 - 19 files changed, 45 insertions(+), 44 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 9dd6cb6e58..2b61091283 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -375,20 +375,28 @@ end -- custom particle effects -local effect = function(pos, amount, texture, min_size, max_size, radius, gravity, glow) +local effect = function(pos, amount, texture, min_size, max_size, radius, gravity, glow, go_down) radius = radius or 2 min_size = min_size or 0.5 max_size = max_size or 1 gravity = gravity or -10 glow = glow or 0 + go_down = go_down or false + + local ym + if go_down then + ym = 0 + else + ym = -radius + end minetest.add_particlespawner({ amount = amount, time = 0.25, minpos = pos, maxpos = pos, - minvel = {x = -radius, y = -radius, z = -radius}, + minvel = {x = -radius, y = ym, z = -radius}, maxvel = {x = radius, y = radius, z = radius}, minacc = {x = 0, y = gravity, z = 0}, maxacc = {x = 0, y = gravity, z = 0}, @@ -401,6 +409,35 @@ local effect = function(pos, amount, texture, min_size, max_size, radius, gravit }) end +local damage_effect = function(self, damage) + -- damage particles + if (not disable_blood) and damage > 0 then + + local amount_large = math.floor(damage / 2) + local amount_small = damage % 2 + + local pos = self.object:get_pos() + + pos.y = pos.y + (self.collisionbox[5] - self.collisionbox[2]) * .5 + + local texture + -- do we have a single blood texture or multiple? + if type(self.blood_texture) == "table" then + texture = self.blood_texture[random(1, #self.blood_texture)] + else + texture = self.blood_texture + end + -- full heart damage (one particle for each 2 HP damage) + if amount_large > 0 then + effect(pos, amount_large, texture, 2, 2, 1.75, 0, nil, true) + end + -- half heart damage (one additional particle if damage is an odd number) + if amount_small > 0 then + -- TODO: Use "half heart" + effect(pos, amount_small, texture, 1, 1, 1.75, 0, nil, true) + end + end +end local update_tag = function(self) self.object:set_properties({ @@ -781,13 +818,14 @@ local do_env_damage = function(self) effect(pos, 2, "bubble.png", nil, nil, 1, nil) if self.breath <= 0 then - -- TODO: Damage particle - effect(pos, 5, "bubble.png", nil, nil, 1, nil) + local dmg if nodef.drowning > 0 then - self.health = self.health - nodef.drowning + dmg = nodef.drowning else - self.health = self.health - 4 + dmg = 4 end + damage_effect(self, dmg) + self.health = self.health - dmg end if check_for_death(self, "drowning", {type = "environment", pos = pos, node = self.standing_in}) then return end @@ -2540,24 +2578,7 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir) }) end - -- blood_particles - if self.blood_amount > 0 - and not disable_blood then - - local pos = self.object:get_pos() - - pos.y = pos.y + (-self.collisionbox[2] + self.collisionbox[5]) * .5 - - -- do we have a single blood texture or multiple? - if type(self.blood_texture) == "table" then - - local blood = self.blood_texture[random(1, #self.blood_texture)] - - effect(pos, self.blood_amount, blood, nil, nil, 1, nil) - else - effect(pos, self.blood_amount, self.blood_texture, nil, nil, 1, nil) - end - end + damage_effect(self, damage) -- do damage self.health = self.health - floor(damage) @@ -3161,7 +3182,6 @@ minetest.register_entity(name, { group_attack = def.group_attack or false, passive = def.passive or false, knock_back = def.knock_back ~= false, - blood_amount = def.blood_amount or 5, blood_texture = def.blood_texture or "mobs_blood.png", shoot_offset = def.shoot_offset or 0, floats = def.floats or 1, -- floats in water by default diff --git a/mods/ENTITIES/mcl_mobs/api.txt b/mods/ENTITIES/mcl_mobs/api.txt index 70ce89ffcf..3ae95dc5d4 100644 --- a/mods/ENTITIES/mcl_mobs/api.txt +++ b/mods/ENTITIES/mcl_mobs/api.txt @@ -123,8 +123,6 @@ functions needed for the mob to work properly which contains the following: e.g. {"player", "mobs_animal:chicken"}. 'runaway_from' contains a table with mob names to run away from, add "player" to list to runaway from player also. - 'blood_amount' contains the number of blood droplets to appear when - mob is hit. 'blood_texture' has the texture name to use for droplets e.g. "mobs_blood.png", or table {"blood1.png", "blood2.png"} 'pathfinding' set to 1 for mobs to use pathfinder feature to locate diff --git a/mods/ENTITIES/mobs_mc/blaze.lua b/mods/ENTITIES/mobs_mc/blaze.lua index 0af6691394..400a5339f3 100644 --- a/mods/ENTITIES/mobs_mc/blaze.lua +++ b/mods/ENTITIES/mobs_mc/blaze.lua @@ -67,7 +67,6 @@ mobs:register_mob("mobs_mc:blaze", { fly = true, jump_chance = 98, fear_height = 0, - blood_amount = 0, glow = 14, }) diff --git a/mods/ENTITIES/mobs_mc/creeper.lua b/mods/ENTITIES/mobs_mc/creeper.lua index 184d9cbe19..07750ff284 100644 --- a/mods/ENTITIES/mobs_mc/creeper.lua +++ b/mods/ENTITIES/mobs_mc/creeper.lua @@ -115,7 +115,6 @@ mobs:register_mob("mobs_mc:creeper", { floats = 1, fear_height = 4, view_range = 16, - blood_amount = 0, }) diff --git a/mods/ENTITIES/mobs_mc/ender_dragon.lua b/mods/ENTITIES/mobs_mc/ender_dragon.lua index 0653c6d0a6..ccd2fe30da 100644 --- a/mods/ENTITIES/mobs_mc/ender_dragon.lua +++ b/mods/ENTITIES/mobs_mc/ender_dragon.lua @@ -60,7 +60,6 @@ mobs:register_mob("mobs_mc:enderdragon", { walk_start = 0, walk_end = 20, run_start = 0, run_end = 20, }, - blood_amount = 0, ignores_nametag = true, }) diff --git a/mods/ENTITIES/mobs_mc/enderman.lua b/mods/ENTITIES/mobs_mc/enderman.lua index ad74768be1..124a2c9df5 100644 --- a/mods/ENTITIES/mobs_mc/enderman.lua +++ b/mods/ENTITIES/mobs_mc/enderman.lua @@ -325,7 +325,6 @@ mobs:register_mob("mobs_mc:enderman", { view_range = 4, fear_height = 4, attack_type = "dogfight", - blood_amount = 0, }) diff --git a/mods/ENTITIES/mobs_mc/endermite.lua b/mods/ENTITIES/mobs_mc/endermite.lua index ebec262da4..5a9793cd45 100644 --- a/mods/ENTITIES/mobs_mc/endermite.lua +++ b/mods/ENTITIES/mobs_mc/endermite.lua @@ -31,7 +31,6 @@ mobs:register_mob("mobs_mc:endermite", { view_range = 16, damage = 2, reach = 1, - blood_amount = 0, }) mobs:register_egg("mobs_mc:endermite", S("Endermite"), "mobs_mc_spawn_icon_endermite.png", 0) diff --git a/mods/ENTITIES/mobs_mc/ghast.lua b/mods/ENTITIES/mobs_mc/ghast.lua index f840653c84..fe14e0e6ee 100644 --- a/mods/ENTITIES/mobs_mc/ghast.lua +++ b/mods/ENTITIES/mobs_mc/ghast.lua @@ -71,7 +71,6 @@ mobs:register_mob("mobs_mc:ghast", { fly = true, fly_in = {"air"}, jump_chance = 98, - blood_amount = 0, }) diff --git a/mods/ENTITIES/mobs_mc/guardian.lua b/mods/ENTITIES/mobs_mc/guardian.lua index 24d0ebd086..503417d212 100644 --- a/mods/ENTITIES/mobs_mc/guardian.lua +++ b/mods/ENTITIES/mobs_mc/guardian.lua @@ -77,7 +77,6 @@ mobs:register_mob("mobs_mc:guardian", { stepheight = 0.1, jump = false, view_range = 16, - blood_amount = 0, }) mobs:spawn_specific("mobs_mc:guardian", mobs_mc.spawn.water, mobs_mc.spawn_water, 0, minetest.LIGHT_MAX+1, 30, 25000, 2, mobs_mc.spawn_height.overworld_min, mobs_mc.spawn_height.water - 10) diff --git a/mods/ENTITIES/mobs_mc/guardian_elder.lua b/mods/ENTITIES/mobs_mc/guardian_elder.lua index f3799baff8..61f5097d49 100644 --- a/mods/ENTITIES/mobs_mc/guardian_elder.lua +++ b/mods/ENTITIES/mobs_mc/guardian_elder.lua @@ -82,7 +82,6 @@ mobs:register_mob("mobs_mc:guardian_elder", { stepheight = 0.1, jump = false, view_range = 16, - blood_amount = 0, }) mobs:spawn_specific("mobs_mc:guardian_elder", mobs_mc.spawn.water, mobs_mc.spawn_water, 0, minetest.LIGHT_MAX+1, 30, 40000, 2, mobs_mc.spawn_height.overworld_min, mobs_mc.spawn_height.water-18) diff --git a/mods/ENTITIES/mobs_mc/horse.lua b/mods/ENTITIES/mobs_mc/horse.lua index d51a1c6602..7eea999ad8 100644 --- a/mods/ENTITIES/mobs_mc/horse.lua +++ b/mods/ENTITIES/mobs_mc/horse.lua @@ -336,7 +336,6 @@ skeleton_horse.sounds = { damage = "mobs_mc_skeleton_hurt", distance = 16, } -skeleton_horse.blood_amount = 0 mobs:register_mob("mobs_mc:skeleton_horse", skeleton_horse) -- Zombie horse diff --git a/mods/ENTITIES/mobs_mc/iron_golem.lua b/mods/ENTITIES/mobs_mc/iron_golem.lua index 95a088decf..046c655ac8 100644 --- a/mods/ENTITIES/mobs_mc/iron_golem.lua +++ b/mods/ENTITIES/mobs_mc/iron_golem.lua @@ -58,7 +58,6 @@ mobs:register_mob("mobs_mc:iron_golem", { punch_start = 40, punch_end = 50, }, jump = true, - blood_amount = 0, }) diff --git a/mods/ENTITIES/mobs_mc/shulker.lua b/mods/ENTITIES/mobs_mc/shulker.lua index 28d60dd18a..0a06fe89c0 100644 --- a/mods/ENTITIES/mobs_mc/shulker.lua +++ b/mods/ENTITIES/mobs_mc/shulker.lua @@ -44,7 +44,6 @@ mobs:register_mob("mobs_mc:shulker", { run_start = 0, run_end = 45, punch_start = 80, punch_end = 100, }, - blood_amount = 0, view_range = 16, fear_height = 4, }) diff --git a/mods/ENTITIES/mobs_mc/silverfish.lua b/mods/ENTITIES/mobs_mc/silverfish.lua index 5bd077a7c3..f2c111987e 100644 --- a/mods/ENTITIES/mobs_mc/silverfish.lua +++ b/mods/ENTITIES/mobs_mc/silverfish.lua @@ -42,7 +42,6 @@ mobs:register_mob("mobs_mc:silverfish", { attack_type = "dogfight", damage = 1, reach = 1, - blood_amount = 0, }) mobs:register_egg("mobs_mc:silverfish", S("Silverfish"), "mobs_mc_spawn_icon_silverfish.png", 0) diff --git a/mods/ENTITIES/mobs_mc/skeleton+stray.lua b/mods/ENTITIES/mobs_mc/skeleton+stray.lua index 128f60c82d..04d402d8da 100644 --- a/mods/ENTITIES/mobs_mc/skeleton+stray.lua +++ b/mods/ENTITIES/mobs_mc/skeleton+stray.lua @@ -83,7 +83,6 @@ local skeleton = { shoot_offset = 1, dogshoot_switch = 1, dogshoot_count_max =1.8, - blood_amount = 0, } mobs:register_mob("mobs_mc:skeleton", skeleton) diff --git a/mods/ENTITIES/mobs_mc/skeleton_wither.lua b/mods/ENTITIES/mobs_mc/skeleton_wither.lua index 1816b177c8..896df69a82 100644 --- a/mods/ENTITIES/mobs_mc/skeleton_wither.lua +++ b/mods/ENTITIES/mobs_mc/skeleton_wither.lua @@ -81,7 +81,6 @@ mobs:register_mob("mobs_mc:witherskeleton", { attack_type = "dogfight", dogshoot_switch = 1, dogshoot_count_max =0.5, - blood_amount = 0, fear_height = 4, }) diff --git a/mods/ENTITIES/mobs_mc/snowman.lua b/mods/ENTITIES/mobs_mc/snowman.lua index c238925e39..48143b4494 100644 --- a/mods/ENTITIES/mobs_mc/snowman.lua +++ b/mods/ENTITIES/mobs_mc/snowman.lua @@ -69,7 +69,6 @@ mobs:register_mob("mobs_mc:snowman", { die_speed = 25, die_loop = false, }, - blood_amount = 0, do_custom = function(self, dtime) if not mobs_griefing then return diff --git a/mods/ENTITIES/mobs_mc/spider.lua b/mods/ENTITIES/mobs_mc/spider.lua index f6ba05e425..5a353c8864 100644 --- a/mods/ENTITIES/mobs_mc/spider.lua +++ b/mods/ENTITIES/mobs_mc/spider.lua @@ -58,7 +58,6 @@ local spider = { run_start = 0, run_end = 20, }, - blood_amount = 0, } mobs:register_mob("mobs_mc:spider", spider) diff --git a/mods/ENTITIES/mobs_mc/wither.lua b/mods/ENTITIES/mobs_mc/wither.lua index db936853ec..871496d006 100644 --- a/mods/ENTITIES/mobs_mc/wither.lua +++ b/mods/ENTITIES/mobs_mc/wither.lua @@ -63,7 +63,6 @@ mobs:register_mob("mobs_mc:wither", { walk_start = 0, walk_end = 20, run_start = 0, run_end = 20, }, - blood_amount = 0, }) local mobs_griefing = minetest.settings:get_bool("mobs_griefing") ~= false