TNT: Add explode_center flag

Add 'explode_centre' flag which when false explodes as normal and when true runs on_blast on centre node as well as dropping items.
This commit is contained in:
tenplus1 2017-08-26 22:14:44 +01:00 committed by rubenwardy
parent bcf98df5fa
commit fe67ffda7c
2 changed files with 12 additions and 4 deletions

View File

@ -363,7 +363,8 @@ TNT API
^ Create an explosion. ^ Create an explosion.
* `position` The center of explosion. * `position` The center of explosion.
* `definition` The TNT definion as passed to `tnt.register` * `definition` The TNT definion as passed to `tnt.register` with the following addition:
* `explode_center` false by default which removes TNT node on blast, when true will explode center node.
`tnt.burn(position, [nodename])` `tnt.burn(position, [nodename])`

View File

@ -208,6 +208,7 @@ local function add_effects(pos, radius, drops)
collisiondetection = false, collisiondetection = false,
vertical = false, vertical = false,
texture = "tnt_boom.png", texture = "tnt_boom.png",
glow = 15,
}) })
minetest.add_particlespawner({ minetest.add_particlespawner({
amount = 64, amount = 64,
@ -272,7 +273,7 @@ function tnt.burn(pos, nodename)
end end
end end
local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owner) local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owner, explode_center)
pos = vector.round(pos) pos = vector.round(pos)
-- scan for adjacent TNT nodes first, and enlarge the explosion -- scan for adjacent TNT nodes first, and enlarge the explosion
local vm1 = VoxelManip() local vm1 = VoxelManip()
@ -286,6 +287,10 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast, owne
local c_tnt_burning = minetest.get_content_id("tnt:tnt_burning") local c_tnt_burning = minetest.get_content_id("tnt:tnt_burning")
local c_tnt_boom = minetest.get_content_id("tnt:boom") local c_tnt_boom = minetest.get_content_id("tnt:boom")
local c_air = minetest.get_content_id("air") local c_air = minetest.get_content_id("air")
-- make sure we still have explosion even when centre node isnt tnt related
if explode_center then
count = 1
end
for z = pos.z - 2, pos.z + 2 do for z = pos.z - 2, pos.z + 2 do
for y = pos.y - 2, pos.y + 2 do for y = pos.y - 2, pos.y + 2 do
@ -384,12 +389,14 @@ end
function tnt.boom(pos, def) function tnt.boom(pos, def)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner") local owner = meta:get_string("owner")
if not def.explode_center then
minetest.set_node(pos, {name = "tnt:boom"})
end
local sound = def.sound or "tnt_explode" local sound = def.sound or "tnt_explode"
minetest.sound_play(sound, {pos = pos, gain = 1.5, minetest.sound_play(sound, {pos = pos, gain = 1.5,
max_hear_distance = math.min(def.radius * 20, 128)}) max_hear_distance = math.min(def.radius * 20, 128)})
minetest.set_node(pos, {name = "tnt:boom"})
local drops, radius = tnt_explode(pos, def.radius, def.ignore_protection, local drops, radius = tnt_explode(pos, def.radius, def.ignore_protection,
def.ignore_on_blast, owner) def.ignore_on_blast, owner, def.explode_center)
-- append entity drops -- append entity drops
local damage_radius = (radius / def.radius) * def.damage_radius local damage_radius = (radius / def.radius) * def.damage_radius
entity_physics(pos, damage_radius, drops) entity_physics(pos, damage_radius, drops)