1
0
Fork 0

Add puncher to tnt_explosions

objects
Wuzzy 2020-05-02 18:21:44 +02:00
parent d4bc7a2f88
commit 6a576c50a0
3 changed files with 13 additions and 7 deletions

View File

@ -134,11 +134,12 @@ end
-- raydirs - The directions for each ray -- raydirs - The directions for each ray
-- radius - The maximum distance each ray will go -- radius - The maximum distance each ray will go
-- drop_chance - The chance that destroyed nodes will drop their items -- 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 -- 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. -- 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 vm = minetest.get_voxel_manip()
local emin, emax = vm:read_from_map(vector.subtract(pos, radius), 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 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())) mcl_death_messages.player_damage(obj, S("@1 was caught in an explosion.", obj:get_player_name()))
end 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) fleshy = damage, knockback = impact * 20.0 } }, punch_dir)
if obj:is_player() then if obj:is_player() then
@ -340,13 +345,14 @@ end
-- pos - The position where the explosion originates from -- pos - The position where the explosion originates from
-- strength - The blast strength of the explosion (a TNT explosion uses 4) -- strength - The blast strength of the explosion (a TNT explosion uses 4)
-- info - Table containing information about explosion. -- info - Table containing information about explosion.
-- puncher - object that is reported as source of punches/damage (optional)
-- --
-- Values in info: -- Values in info:
-- drop_chance - If specified becomes the drop chance of all nodes in the -- drop_chance - If specified becomes the drop chance of all nodes in the
-- explosion (defaults to 1.0 / strength) -- explosion (defaults to 1.0 / strength)
-- no_sound - If true then the explosion will not play a sound -- no_sound - If true then the explosion will not play a sound
-- no_particle - If true then the explosion will not create particles -- 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) -- The maximum blast radius (in the air)
local radius = math.ceil(1.3 * strength / (0.3 * 0.75) * 0.3) 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 end
shape = sphere_shapes[radius] 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 if not (info and info.no_sound) then
add_particles(pos, radius) add_particles(pos, radius)

View File

@ -183,7 +183,7 @@ minetest.register_on_dieplayer(function(player, reason)
-- Player -- Player
elseif hitter:is_player() then elseif hitter:is_player() then
hittername = hitter:get_player_name() hittername = hitter:get_player_name()
if hittername ~= nil and hittername ~= name then if hittername ~= nil then
msg = dmsg("murder", name, hittername) msg = dmsg("murder", name, hittername)
else else
msg = dmsg("murder_any", name) msg = dmsg("murder_any", name)

View File

@ -210,7 +210,7 @@ function TNT:on_step(dtime)
self.blinkstatus = not self.blinkstatus self.blinkstatus = not self.blinkstatus
end end
if self.timer > tnt.BOOMTIMER then 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() self.object:remove()
end end
end end