From cc119a717c48b803ef95c7e1230644a85afcf569 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 16 Jan 2017 14:59:16 +0100 Subject: [PATCH] Fix TNT ignition --- mods/default/functions.lua | 8 ++++---- mods/default/tools.lua | 8 ++++++-- mods/tnt/init.lua | 28 ++++++++++++---------------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/mods/default/functions.lua b/mods/default/functions.lua index fffdd1bb5..373deb7e2 100644 --- a/mods/default/functions.lua +++ b/mods/default/functions.lua @@ -195,10 +195,10 @@ function get_nodedef_field(nodename, fieldname) end function set_fire(pointed_thing) - local n = minetest.get_node(pointed_thing.above) - if n.name ~= "" and n.name == "air" and not minetest.is_protected(pointed_thing.above, "fire") then - minetest.add_node(pointed_thing.above, {name="fire:basic_flame"}) - end + local n = minetest.get_node(pointed_thing.above) + if n.name ~= "" and n.name == "air" and not minetest.is_protected(pointed_thing.above, "fire") then + minetest.add_node(pointed_thing.above, {name="fire:basic_flame"}) + end end -- diff --git a/mods/default/tools.lua b/mods/default/tools.lua index 930faad73..597aa5663 100644 --- a/mods/default/tools.lua +++ b/mods/default/tools.lua @@ -289,9 +289,13 @@ minetest.register_tool("default:flint_and_steel", { }, on_use = function(itemstack, user, pointed_thing) if pointed_thing.type == "node" then + if minetest.get_node(pointed_thing.under).name == "tnt:tnt" then + tnt.ignite(pointed_thing.under) + else set_fire(pointed_thing) - itemstack:add_wear(66000/65) -- 65 uses - return itemstack + itemstack:add_wear(66000/65) -- 65 uses + return itemstack + end end end, }) diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index 030bccd2f..8a519606e 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -1,16 +1,16 @@ -function spawn_tnt(pos, entname) +local function spawn_tnt(pos, entname) minetest.sound_play("tnt_ignite", {pos = pos,gain = 1.0,max_hear_distance = 15,}) return minetest.add_entity(pos, entname) end -function activate_if_tnt(nname, np, tnt_np, tntr) +local function activate_if_tnt(nname, np, tnt_np, tntr) if nname == "tnt:tnt" then local e = spawn_tnt(np, nname) e:setvelocity({x=(np.x - tnt_np.x)*5+(tntr / 4), y=(np.y - tnt_np.y)*5+(tntr / 3), z=(np.z - tnt_np.z)*5+(tntr / 4)}) end end -function do_tnt_physics(tnt_np,tntr) +local function do_tnt_physics(tnt_np,tntr) local objs = minetest.get_objects_inside_radius(tnt_np, tntr) for k, obj in pairs(objs) do local oname = obj:get_entity_name() @@ -30,6 +30,14 @@ function do_tnt_physics(tnt_np,tntr) end end +tnt = {} +tnt.ignite = function(pos) + minetest.remove_node(pos) + spawn_tnt(pos, "tnt:tnt") + nodeupdate(pos) +end + + minetest.register_node("tnt:tnt", { tiles = {"default_tnt_top.png", "default_tnt_bottom.png", "default_tnt_side.png", "default_tnt_side.png", @@ -39,23 +47,11 @@ minetest.register_node("tnt:tnt", { stack_max = 64, description = "TNT", mesecons = {effector = { - action_on = (function(p, node) - minetest.remove_node(p) - spawn_tnt(p, "tnt:tnt") - nodeupdate(p) - end), + action_on = tnt.ignite }}, sounds = default.node_sound_wood_defaults(), }) -minetest.register_on_punchnode(function(p, node) - if node.name == "tnt:tnt" then - minetest.remove_node(p) - spawn_tnt(p, "tnt:tnt") - nodeupdate(p) - end -end) - local TNT_RANGE = 3 local TNT = { -- Static definition