+
+function tnt.register_tnt(def)
+ local name = ""
+ if not def.name:find(':') then
+ name = "tnt:" .. def.name
+ else
+ name = def.name
+ def.name = def.name:match(":([%w_]+)")
+ end
+ if not def.tiles then def.tiles = {} end
+ local tnt_top = def.tiles.top or def.name .. "_top.png"
+ local tnt_bottom = def.tiles.bottom or def.name .. "_bottom.png"
+ local tnt_side = def.tiles.side or def.name .. "_side.png"
+ local tnt_burning = def.tiles.burning or def.name .. "_top_burning_animated.png"
+ if not def.damage_radius then def.damage_radius = def.radius * 2 end
+
+ minetest.register_node(":" .. name, {
+ description = def.description,
+ tiles = {tnt_top, tnt_bottom, tnt_side},
+ is_ground_content = false,
+ groups = {dig_immediate = 2, mesecon = 2, tnt = 1},
+ sounds = default.node_sound_wood_defaults(),
+ on_punch = function(pos, node, puncher)
+ 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.get_node_timer(pos):start(4)
+ end
+ end,
+ on_blast = function(pos, intensity)
+ tnt.burn(pos)
+ end,
+ mesecons = {effector =
+ {action_on =
+ function(pos)
+ tnt.boom(pos, def)
+ end
+ }
+ },
+ })
+
+ minetest.register_node(":" .. name .. "_burning", {
+ tiles = {
+ {
+ name = tnt_burning,
+ animation = {
+ type = "vertical_frames",
+ aspect_w = 16,
+ aspect_h = 16,
+ length = 1,
+ }
+ },
+ tnt_bottom, tnt_side
+ },
+ light_source = 5,
+ drop = "",
+ sounds = default.node_sound_wood_defaults(),
+ on_timer = function(pos, elapsed)
+ tnt.boom(pos, def)
+ end,
+ -- unaffected by explosions
+ on_blast = function() end,
+ })
+end
+
+tnt.register_tnt({
+ name = "tnt:tnt",
+ description = "TNT",
+ radius = radius,
+})
+