Fix TNT ignition

This commit is contained in:
Wuzzy 2017-01-16 14:59:16 +01:00
parent 674a989061
commit cc119a717c
3 changed files with 22 additions and 22 deletions

View File

@ -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
--

View File

@ -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,
})

View File

@ -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