Update tnt mod

master
vlapsley 2017-08-17 21:46:26 +10:00
parent 21c3cf6662
commit 2011fd3790
24 changed files with 55 additions and 17 deletions

View File

@ -31,7 +31,10 @@ in mining.
How to use the mod:
Craft gunpowder by placing coal and gravel in the crafting area.
The gunpowder can be used to craft TNT or as fuse for TNT.
To craft TNT surround gunpowder with 4 wood in a + shape.
To craft TNT place items like this:
-- wood - gunpowder -- wood -
gunpowder gunpowder gunpowder
-- wood - gunpowder -- wood -
There are different ways to blow up TNT:
1. Hit it with a torch.

View File

@ -1,7 +1,7 @@
tnt = {}
-- Default to enabled when in singleplayer
local enable_tnt = minetest.setting_getbool("enable_tnt")
local enable_tnt = minetest.settings:get_bool("enable_tnt")
if enable_tnt == nil then
enable_tnt = minetest.is_singleplayer()
end
@ -12,7 +12,7 @@ local loss_prob = {}
loss_prob["default:cobble"] = 3
loss_prob["default:dirt"] = 4
local tnt_radius = tonumber(minetest.setting_get("tnt_radius") or 3)
local tnt_radius = tonumber(minetest.settings:get("tnt_radius") or 3)
-- Fill a list with data for content IDs, after all nodes are registered
local cid_data = {}
@ -83,7 +83,10 @@ local function add_drop(drops, item)
end
end
local function destroy(drops, npos, cid, c_air, c_fire, on_blast_queue, ignore_protection, ignore_on_blast)
local basic_flame_on_construct -- cached value
local function destroy(drops, npos, cid, c_air, c_fire,
on_blast_queue, on_construct_queue,
ignore_protection, ignore_on_blast)
if not ignore_protection and minetest.is_protected(npos, "") then
return cid
end
@ -93,9 +96,16 @@ local function destroy(drops, npos, cid, c_air, c_fire, on_blast_queue, ignore_p
if not def then
return c_air
elseif not ignore_on_blast and def.on_blast then
on_blast_queue[#on_blast_queue + 1] = {pos = vector.new(npos), on_blast = def.on_blast}
on_blast_queue[#on_blast_queue + 1] = {
pos = vector.new(npos),
on_blast = def.on_blast
}
return cid
elseif def.flammable then
on_construct_queue[#on_construct_queue + 1] = {
fn = basic_flame_on_construct,
pos = vector.new(npos)
}
return c_fire
else
local node_drops = minetest.get_node_drops(def.name, "")
@ -250,13 +260,15 @@ end
function tnt.burn(pos, nodename)
local name = nodename or minetest.get_node(pos).name
local group = minetest.get_item_group(name, "tnt")
if group > 0 then
local def = minetest.registered_nodes[name]
if not def then
return
elseif def.on_ignite then
def.on_ignite(pos)
elseif minetest.get_item_group(name, "tnt") > 0 then
minetest.sound_play("tnt_ignite", {pos = pos})
minetest.set_node(pos, {name = name .. "_burning"})
minetest.get_node_timer(pos):start(1)
elseif name == "tnt:gunpowder" then
minetest.set_node(pos, {name = "tnt:gunpowder_burning"})
end
end
@ -306,6 +318,8 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast)
local drops = {}
local on_blast_queue = {}
local on_construct_queue = {}
basic_flame_on_construct = minetest.registered_nodes["fire:basic_flame"].on_construct
local c_fire = minetest.get_content_id("fire:basic_flame")
for z = -radius, radius do
@ -318,8 +332,8 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast)
local p = {x = pos.x + x, y = pos.y + y, z = pos.z + z}
if cid ~= c_air then
data[vi] = destroy(drops, p, cid, c_air, c_fire,
on_blast_queue, ignore_protection,
ignore_on_blast)
on_blast_queue, on_construct_queue,
ignore_protection, ignore_on_blast)
end
end
vi = vi + 1
@ -357,6 +371,10 @@ local function tnt_explode(pos, radius, ignore_protection, ignore_on_blast)
end
end
for _, queued_data in pairs(on_construct_queue) do
queued_data.fn(queued_data.pos)
end
return drops, radius
end
@ -372,6 +390,8 @@ function tnt.boom(pos, def)
eject_drops(drops, pos, radius)
end
add_effects(pos, radius, drops)
minetest.log("action", "A TNT explosion occurred at " .. minetest.pos_to_string(pos) ..
" with radius " .. radius)
end
minetest.register_node("tnt:boom", {
@ -397,7 +417,12 @@ minetest.register_node("tnt:gunpowder", {
is_ground_content = false,
sunlight_propagates = true,
walkable = false,
tiles = {"tnt_gunpowder_straight.png", "tnt_gunpowder_curved.png", "tnt_gunpowder_t_junction.png", "tnt_gunpowder_crossing.png"},
tiles = {
"tnt_gunpowder_straight.png",
"tnt_gunpowder_curved.png",
"tnt_gunpowder_t_junction.png",
"tnt_gunpowder_crossing.png"
},
inventory_image = "tnt_gunpowder_inventory.png",
wield_image = "tnt_gunpowder_inventory.png",
selection_box = {
@ -411,6 +436,9 @@ minetest.register_node("tnt:gunpowder", {
on_punch = function(pos, node, puncher)
if puncher:get_wielded_item():get_name() == "default:torch" then
minetest.set_node(pos, {name = "tnt:gunpowder_burning"})
minetest.log("action", puncher:get_player_name() ..
" ignites tnt:gunpowder at " ..
minetest.pos_to_string(pos))
end
end,
on_blast = function(pos, intensity)
@ -471,7 +499,11 @@ minetest.register_node("tnt:gunpowder_burning", {
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
drop = "",
groups = {dig_immediate = 2, attached_node = 1, connect_to_raillike = minetest.raillike_group("gunpowder")},
groups = {
dig_immediate = 2,
attached_node = 1,
connect_to_raillike = minetest.raillike_group("gunpowder")
},
sounds = default.node_sound_leaves_defaults(),
on_timer = function(pos, elapsed)
for dx = -1, 1 do
@ -498,7 +530,7 @@ minetest.register_node("tnt:gunpowder_burning", {
})
minetest.register_craft({
output = "tnt:gunpowder",
output = "tnt:gunpowder 5",
type = "shapeless",
recipe = {"default:coal_lump", "default:gravel"}
})
@ -507,9 +539,9 @@ if enable_tnt then
minetest.register_craft({
output = "tnt:tnt",
recipe = {
{"", "group:wood", ""},
{"group:wood", "tnt:gunpowder", "group:wood"},
{"", "group:wood", ""}
{"group:wood", "tnt:gunpowder", "group:wood"},
{"tnt:gunpowder", "tnt:gunpowder", "tnt:gunpowder"},
{"group:wood", "tnt:gunpowder", "group:wood"}
}
})
@ -550,6 +582,9 @@ function tnt.register_tnt(def)
on_punch = function(pos, node, puncher)
if puncher:get_wielded_item():get_name() == "default:torch" then
minetest.set_node(pos, {name = name .. "_burning"})
minetest.log("action", puncher:get_player_name() ..
" ignites " .. node.name .. " at " ..
minetest.pos_to_string(pos))
end
end,
on_blast = function(pos, intensity)

View File

Before

Width:  |  Height:  |  Size: 855 B

After

Width:  |  Height:  |  Size: 855 B

View File

Before

Width:  |  Height:  |  Size: 178 B

After

Width:  |  Height:  |  Size: 178 B

View File

Before

Width:  |  Height:  |  Size: 99 B

After

Width:  |  Height:  |  Size: 99 B

View File

Before

Width:  |  Height:  |  Size: 612 B

After

Width:  |  Height:  |  Size: 612 B

View File

Before

Width:  |  Height:  |  Size: 432 B

After

Width:  |  Height:  |  Size: 432 B

View File

Before

Width:  |  Height:  |  Size: 461 B

After

Width:  |  Height:  |  Size: 461 B

View File

Before

Width:  |  Height:  |  Size: 672 B

After

Width:  |  Height:  |  Size: 672 B

View File

Before

Width:  |  Height:  |  Size: 245 B

After

Width:  |  Height:  |  Size: 245 B

View File

Before

Width:  |  Height:  |  Size: 268 B

After

Width:  |  Height:  |  Size: 268 B

View File

Before

Width:  |  Height:  |  Size: 301 B

After

Width:  |  Height:  |  Size: 301 B

View File

Before

Width:  |  Height:  |  Size: 225 B

After

Width:  |  Height:  |  Size: 225 B

View File

Before

Width:  |  Height:  |  Size: 328 B

After

Width:  |  Height:  |  Size: 328 B

View File

Before

Width:  |  Height:  |  Size: 128 B

After

Width:  |  Height:  |  Size: 128 B

View File

Before

Width:  |  Height:  |  Size: 202 B

After

Width:  |  Height:  |  Size: 202 B

View File

Before

Width:  |  Height:  |  Size: 148 B

After

Width:  |  Height:  |  Size: 148 B

View File

Before

Width:  |  Height:  |  Size: 159 B

After

Width:  |  Height:  |  Size: 159 B

View File

Before

Width:  |  Height:  |  Size: 238 B

After

Width:  |  Height:  |  Size: 238 B