Skip to content

Commit

Permalink
Secure TNT
Browse files Browse the repository at this point in the history
  • Loading branch information
acmgit committed Feb 12, 2024
1 parent 10799db commit 7ab3947
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion mods/tnt/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ tnt = {}
-- Load support for MT game translation.
local S = minetest.get_translator("tnt")


-- Default to enabled when in singleplayer
local enable_tnt = minetest.settings:get_bool("enable_tnt")
if enable_tnt == nil then
Expand All @@ -19,6 +18,7 @@ loss_prob["default:cobble"] = 3
loss_prob["default:dirt"] = 4

local tnt_radius = tonumber(minetest.settings:get("tnt_radius") or 3)
local tnt_height = tonumber(minetest.settings:get("tnt_work_below_height") or 31000)

-- Fill a list with data for content IDs, after all nodes are registered
local cid_data = {}
Expand Down Expand Up @@ -278,6 +278,7 @@ function tnt.burn(pos, nodename)
elseif def.on_ignite then
def.on_ignite(pos)
elseif minetest.get_item_group(name, "tnt") > 0 then
if(pos.y > tnt_height) then return end
minetest.swap_node(pos, {name = name .. "_burning"})
minetest.sound_play("tnt_ignite", {pos = pos, gain = 1.0}, true)
minetest.get_node_timer(pos):start(1)
Expand Down Expand Up @@ -464,18 +465,22 @@ minetest.register_node("tnt:gunpowder", {
sounds = default.node_sound_leaves_defaults(),

on_punch = function(pos, node, puncher)
if(pos.y > tnt_height) then return end
if puncher:get_wielded_item():get_name() == "default:torch" then
minetest.set_node(pos, {name = "tnt:gunpowder_burning"})
default.log_player_action(puncher, "ignites tnt:gunpowder at", pos)
end
end,
on_blast = function(pos, intensity)
if(pos.y > tnt_height) then return end
minetest.set_node(pos, {name = "tnt:gunpowder_burning"})
end,
on_burn = function(pos)
if(pos.y > tnt_height) then return end
minetest.set_node(pos, {name = "tnt:gunpowder_burning"})
end,
on_ignite = function(pos, igniter)
if(pos.y > tnt_height) then return end
minetest.set_node(pos, {name = "tnt:gunpowder_burning"})
end,
})
Expand Down Expand Up @@ -632,28 +637,33 @@ function tnt.register_tnt(def)
end,
on_punch = function(pos, node, puncher)
if puncher:get_wielded_item():get_name() == "default:torch" then
if(pos.y > tnt_height) then return end
minetest.swap_node(pos, {name = name .. "_burning"})
minetest.registered_nodes[name .. "_burning"].on_construct(pos)
default.log_player_action(puncher, "ignites", node.name, "at", pos)
end
end,
on_blast = function(pos, intensity)
if(pos.y > tnt_height) then return end
minetest.after(0.1, function()
tnt.boom(pos, def)
end)
end,
mesecons = {effector =
{action_on =
function(pos)
if(pos.y > tnt_height) then return end
tnt.boom(pos, def)
end
}
},
on_burn = function(pos)
if(pos.y > tnt_height) then return end
minetest.swap_node(pos, {name = name .. "_burning"})
minetest.registered_nodes[name .. "_burning"].on_construct(pos)
end,
on_ignite = function(pos, igniter)
if(pos.y > tnt_height) then return end
minetest.swap_node(pos, {name = name .. "_burning"})
minetest.registered_nodes[name .. "_burning"].on_construct(pos)
end,
Expand Down Expand Up @@ -683,6 +693,7 @@ function tnt.register_tnt(def)
-- unaffected by explosions
on_blast = function() end,
on_construct = function(pos)
if(pos.y > tnt_height) then return end
minetest.sound_play("tnt_ignite", {pos = pos}, true)
minetest.get_node_timer(pos):start(4)
minetest.check_for_falling(pos)
Expand Down
3 changes: 3 additions & 0 deletions settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ enable_tnt (TNT) bool true
# The radius in which nodes will be destroyed by a TNT explosion.
tnt_radius (TNT radius) int 3 0

# The height below tnt can explode.
tnt_work_below_height (Under tnt explodes) int 31000

# Sets the behaviour of the inventory items when a player dies.
# bones: Store items in a bone node but drop items if inside protected area.
# drop: Drop items on the ground.
Expand Down

0 comments on commit 7ab3947

Please sign in to comment.