From 6a576c50a07b22cd84fa7141daae5ffafcbde5b2 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 2 May 2020 18:21:44 +0200 Subject: [PATCH] Add puncher to tnt_explosions --- mods/CORE/mcl_explosions/init.lua | 16 +++++++++++----- mods/HUD/mcl_death_messages/init.lua | 2 +- mods/ITEMS/mcl_tnt/init.lua | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/mods/CORE/mcl_explosions/init.lua b/mods/CORE/mcl_explosions/init.lua index 99cdb0feb..de8768ca3 100644 --- a/mods/CORE/mcl_explosions/init.lua +++ b/mods/CORE/mcl_explosions/init.lua @@ -134,11 +134,12 @@ end -- raydirs - The directions for each ray -- radius - The maximum distance each ray will go -- drop_chance - The chance that destroyed nodes will drop their items +-- puncher - object that punches other objects (optional) -- -- Note that this function has been optimized, it contains code which has been --- inlined to avoid function calls and unnecessary table creation. This was +-- inlined to avoid function calls and unnecessary table creation. This was -- measured to give a significant performance increase. -local function trace_explode(pos, strength, raydirs, radius, drop_chance) +local function trace_explode(pos, strength, raydirs, radius, drop_chance, puncher) local vm = minetest.get_voxel_manip() local emin, emax = vm:read_from_map(vector.subtract(pos, radius), @@ -285,7 +286,11 @@ local function trace_explode(pos, strength, raydirs, radius, drop_chance) if mod_death_messages and obj:is_player() then mcl_death_messages.player_damage(obj, S("@1 was caught in an explosion.", obj:get_player_name())) end - obj:punch(obj, 10, { damage_groups = { full_punch_interval = 1, + local source = puncher + if not source then + source = obj + end + obj:punch(source, 10, { damage_groups = { full_punch_interval = 1, fleshy = damage, knockback = impact * 20.0 } }, punch_dir) if obj:is_player() then @@ -340,13 +345,14 @@ end -- pos - The position where the explosion originates from -- strength - The blast strength of the explosion (a TNT explosion uses 4) -- info - Table containing information about explosion. +-- puncher - object that is reported as source of punches/damage (optional) -- -- Values in info: -- drop_chance - If specified becomes the drop chance of all nodes in the -- explosion (defaults to 1.0 / strength) -- no_sound - If true then the explosion will not play a sound -- no_particle - If true then the explosion will not create particles -function mcl_explosions.explode(pos, strength, info) +function mcl_explosions.explode(pos, strength, info, puncher) -- The maximum blast radius (in the air) local radius = math.ceil(1.3 * strength / (0.3 * 0.75) * 0.3) @@ -355,7 +361,7 @@ function mcl_explosions.explode(pos, strength, info) end shape = sphere_shapes[radius] - trace_explode(pos, strength, shape, radius, (info and info.drop_chance) or 1 / strength) + trace_explode(pos, strength, shape, radius, (info and info.drop_chance) or 1 / strength, puncher) if not (info and info.no_sound) then add_particles(pos, radius) diff --git a/mods/HUD/mcl_death_messages/init.lua b/mods/HUD/mcl_death_messages/init.lua index 25be93263..dfc5191a6 100644 --- a/mods/HUD/mcl_death_messages/init.lua +++ b/mods/HUD/mcl_death_messages/init.lua @@ -183,7 +183,7 @@ minetest.register_on_dieplayer(function(player, reason) -- Player elseif hitter:is_player() then hittername = hitter:get_player_name() - if hittername ~= nil and hittername ~= name then + if hittername ~= nil then msg = dmsg("murder", name, hittername) else msg = dmsg("murder_any", name) diff --git a/mods/ITEMS/mcl_tnt/init.lua b/mods/ITEMS/mcl_tnt/init.lua index 0ec2679b8..68a1296bf 100644 --- a/mods/ITEMS/mcl_tnt/init.lua +++ b/mods/ITEMS/mcl_tnt/init.lua @@ -210,7 +210,7 @@ function TNT:on_step(dtime) self.blinkstatus = not self.blinkstatus end if self.timer > tnt.BOOMTIMER then - mcl_explosions.explode(self.object:get_pos(), 4, { drop_chance = 1.0 }) + mcl_explosions.explode(self.object:get_pos(), 4, { drop_chance = 1.0 }, self.object) self.object:remove() end end