forked from VoxeLibre/VoxeLibre
Improve API of mcl_explosions.explode
Replace the 'no_sound' and 'no_particle' options in the 'info' parameter with 'sound' and 'particles'. But also has backwards compatability for the old parameter names.
This commit is contained in:
parent
c907df9669
commit
4a07b0607f
|
@ -384,16 +384,20 @@ end
|
||||||
-- Parameters:
|
-- Parameters:
|
||||||
-- 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)
|
-- 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 (default: 1.0 / strength)
|
||||||
-- no_sound - If true then the explosion will not play a sound
|
-- sound - If true, the explosion will play a sound (default: true)
|
||||||
-- no_particle - If true then the explosion will not create particles
|
-- particles - If true, the explosion will create particles (default: true)
|
||||||
-- fire - If true, 1/3 nodes become fire (default: false)
|
-- fire - If true, 1/3 nodes become fire (default: false)
|
||||||
function mcl_explosions.explode(pos, strength, info, puncher)
|
function mcl_explosions.explode(pos, strength, info, puncher)
|
||||||
|
if info == nil then
|
||||||
|
info = {}
|
||||||
|
end
|
||||||
|
|
||||||
-- 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)
|
||||||
|
|
||||||
|
@ -402,13 +406,26 @@ function mcl_explosions.explode(pos, strength, info, puncher)
|
||||||
end
|
end
|
||||||
local shape = sphere_shapes[radius]
|
local shape = sphere_shapes[radius]
|
||||||
|
|
||||||
local creative_enabled = minetest.is_creative_enabled("")
|
local drop_chance = info.drop_change ~= nil and info.drop_change or 1 / strength
|
||||||
trace_explode(pos, strength, shape, radius, (info and info.drop_chance) or 1 / strength, info.fire, puncher, creative_enabled)
|
local particles = info.particles ~= nil and info.particles or true
|
||||||
|
local sound = info.sound ~= nil and info.sound or true
|
||||||
|
local fire = info.fire ~= nil and info.fire or false
|
||||||
|
|
||||||
if not (info and info.no_particle) then
|
-- For backwards compatability
|
||||||
|
if info.no_particle then
|
||||||
|
particles = false
|
||||||
|
end
|
||||||
|
if info.no_sound then
|
||||||
|
sound = false
|
||||||
|
end
|
||||||
|
|
||||||
|
local creative_enabled = minetest.is_creative_enabled("")
|
||||||
|
trace_explode(pos, strength, shape, radius, drop_chance, fire, puncher, creative_enabled)
|
||||||
|
|
||||||
|
if particles then
|
||||||
add_particles(pos, radius)
|
add_particles(pos, radius)
|
||||||
end
|
end
|
||||||
if not (info and info.no_sound) then
|
if sound then
|
||||||
minetest.sound_play("tnt_explode", {
|
minetest.sound_play("tnt_explode", {
|
||||||
pos = pos, gain = 1.0,
|
pos = pos, gain = 1.0,
|
||||||
max_hear_distance = strength * 16
|
max_hear_distance = strength * 16
|
||||||
|
|
Loading…
Reference in New Issue