Added support for on_blast callback

This commit is contained in:
Wuzzy 2013-09-24 23:28:58 +02:00
parent d6a0b7dfec
commit 4427d79641

View File

@ -1,7 +1,13 @@
local destroy = function(pos) local destroy = function(pos)
local nodename = minetest.env:get_node(pos).name local nodename = minetest.env:get_node(pos).name
if nodename ~= "air" then if nodename ~= "air" then
local on_blast = minetest.registered_nodes[nodename].on_blast
if on_blast ~= nil then
on_blast(pos, 1) -- the intensity of TNT is defined to be 1
return
else
minetest.env:remove_node(pos) minetest.env:remove_node(pos)
end
nodeupdate(pos) nodeupdate(pos)
if minetest.registered_nodes[nodename].groups.flammable ~= nil then if minetest.registered_nodes[nodename].groups.flammable ~= nil then
minetest.env:set_node(pos, {name="fire:basic_flame"}) minetest.env:set_node(pos, {name="fire:basic_flame"})
@ -68,10 +74,7 @@ boom = function(pos, time)
pos.z = pos.z+dz pos.z = pos.z+dz
local node = minetest.env:get_node(pos) local node = minetest.env:get_node(pos)
if node.name == "tnt:tnt" or node.name == "tnt:tnt_burning" then if node.name == "fire:basic_flame" or string.find(node.name, "default:water_") or string.find(node.name, "default:lava_") or node.name == "tnt:boom" then
minetest.env:set_node(pos, {name="tnt:tnt_burning"})
boom({x=pos.x, y=pos.y, z=pos.z}, 0)
elseif node.name == "fire:basic_flame" or string.find(node.name, "default:water_") or string.find(node.name, "default:lava_") or node.name == "tnt:boom" then
else else
if math.abs(dx)<2 and math.abs(dy)<2 and math.abs(dz)<2 then if math.abs(dx)<2 and math.abs(dy)<2 and math.abs(dz)<2 then
@ -123,6 +126,11 @@ minetest.register_node("tnt:tnt", {
end end
end, end,
on_blast = function(pos, intensity)
minetest.env:set_node(pos, {name="tnt:tnt_burning"})
boom({x=pos.x, y=pos.y, z=pos.z}, 0)
end,
mesecons = { mesecons = {
effector = { effector = {
action_on = function(pos, node) action_on = function(pos, node)
@ -138,6 +146,9 @@ minetest.register_node("tnt:tnt_burning", {
light_source = 5, light_source = 5,
drop = "", drop = "",
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
on_blast = function(pos, intensity)
boom({x=pos.x, y=pos.y, z=pos.z}, 0)
end,
}) })
minetest.register_node("tnt:boom", { minetest.register_node("tnt:boom", {