TNT: Move timer start to on_create() for burning nodes.

We add on_create() handlers for both burning TNT and burning
gunpowder. Because gunpowder will explode TNT in 1 second,
and not 4, we need to modify the 4 second timer after we
make the TNT burning. Other mods can now place burning TNT
that will by default explode after 4 seconds.
This commit is contained in:
Auke Kok 2016-03-29 07:39:46 -07:00 committed by paramat
parent 0736d30e33
commit e6cef57661

@ -198,9 +198,7 @@ function tnt.burn(pos)
minetest.set_node(pos, {name = name .. "_burning"}) minetest.set_node(pos, {name = name .. "_burning"})
minetest.get_node_timer(pos):start(1) minetest.get_node_timer(pos):start(1)
elseif name == "tnt:gunpowder" then elseif name == "tnt:gunpowder" then
minetest.sound_play("tnt_gunpowder_burning", {pos = pos, gain = 2})
minetest.set_node(pos, {name = "tnt:gunpowder_burning"}) minetest.set_node(pos, {name = "tnt:gunpowder_burning"})
minetest.get_node_timer(pos):start(1)
end end
end end
@ -378,6 +376,10 @@ minetest.register_node("tnt:gunpowder_burning", {
end, end,
-- unaffected by explosions -- unaffected by explosions
on_blast = function() end, on_blast = function() end,
on_construct = function(pos)
minetest.sound_play("tnt_gunpowder_burning", {pos = pos, gain = 2})
minetest.get_node_timer(pos):start(1)
end,
}) })
minetest.register_abm({ minetest.register_abm({
@ -426,9 +428,7 @@ function tnt.register_tnt(def)
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_punch = function(pos, node, puncher) on_punch = function(pos, node, puncher)
if puncher:get_wielded_item():get_name() == "default:torch" then if puncher:get_wielded_item():get_name() == "default:torch" then
minetest.sound_play("tnt_ignite", {pos = pos})
minetest.set_node(pos, {name = name .. "_burning"}) minetest.set_node(pos, {name = name .. "_burning"})
minetest.get_node_timer(pos):start(4)
end end
end, end,
on_blast = function(pos, intensity) on_blast = function(pos, intensity)
@ -466,6 +466,10 @@ function tnt.register_tnt(def)
end, end,
-- unaffected by explosions -- unaffected by explosions
on_blast = function() end, on_blast = function() end,
on_construct = function(pos)
minetest.sound_play("tnt_ignite", {pos = pos})
minetest.get_node_timer(pos):start(4)
end,
}) })
end end