From 47636791b157ca5744a538823ae9c3f6b879b4e5 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 7 Mar 2015 08:32:00 +0100 Subject: [PATCH 1/6] Make TNT respect on_blast, implement on_blast for some nodes Implemented nodes: - Steel Door: Ignores explosion - Locked Chest: Ignores explosion - Fire: Ignores explosion - TNT: Starts burning - Burning TNT: Explodes immediately - Gunpowder: Starts burning - Burning Gunpowder: Ignores explosion --- mods/default/nodes.lua | 1 + mods/doors/init.lua | 15 +++++++++++---- mods/fire/init.lua | 2 ++ mods/tnt/init.lua | 34 +++++++++++++++++++--------------- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index e64bd101..5e019659 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -1234,6 +1234,7 @@ minetest.register_node("default:chest_locked", { ) end end, + on_blast = function() end, }) diff --git a/mods/doors/init.lua b/mods/doors/init.lua index 7c2cf1c7..2b326b07 100644 --- a/mods/doors/init.lua +++ b/mods/doors/init.lua @@ -25,6 +25,9 @@ function doors.register_door(name, def) if not def.sound_open_door then def.sound_open_door = "doors_door_open" end + if def.only_placer_can_open then + def.on_blast = function() end + end minetest.register_craftitem(name, { @@ -173,7 +176,8 @@ function doors.register_door(name, def) can_dig = check_player_priv, sounds = def.sounds, - sunlight_propagates = def.sunlight + sunlight_propagates = def.sunlight, + on_blast = def.on_blast, }) minetest.register_node(name.."_t_1", { @@ -205,7 +209,8 @@ function doors.register_door(name, def) can_dig = check_player_priv, sounds = def.sounds, - sunlight_propagates = def.sunlight, + sunlight_propagates = def.sunlight, + on_blast = def.on_blast, }) minetest.register_node(name.."_b_2", { @@ -237,7 +242,8 @@ function doors.register_door(name, def) can_dig = check_player_priv, sounds = def.sounds, - sunlight_propagates = def.sunlight + sunlight_propagates = def.sunlight, + on_blast = def.on_blast, }) minetest.register_node(name.."_t_2", { @@ -269,7 +275,8 @@ function doors.register_door(name, def) can_dig = check_player_priv, sounds = def.sounds, - sunlight_propagates = def.sunlight + sunlight_propagates = def.sunlight, + on_blast = def.on_blast, }) end diff --git a/mods/fire/init.lua b/mods/fire/init.lua index f932b0c5..c07ad35f 100644 --- a/mods/fire/init.lua +++ b/mods/fire/init.lua @@ -24,6 +24,8 @@ minetest.register_node("fire:basic_flame", { on_destruct = function(pos) minetest.after(0, fire.on_flame_remove_at, pos) end, + + on_blast = function() end, }) fire.D = 6 diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index fda4ec39..94925b75 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -82,7 +82,14 @@ local function destroy(drops, pos, cid) if def and def.flammable then minetest.set_node(pos, fire_node) else - minetest.remove_node(pos) + local nodename = minetest.get_node(pos).name + local on_blast = minetest.registered_nodes[nodename].on_blast + if on_blast ~= nil then + on_blast(pos, 1) + return + else + minetest.remove_node(pos) + end if def then local node_drops = minetest.get_node_drops(def.name, "") for _, item in ipairs(node_drops) do @@ -172,12 +179,6 @@ local function explode(pos, radius) local p = {} local c_air = minetest.get_content_id("air") - local c_tnt = minetest.get_content_id("tnt:tnt") - local c_tnt_burning = minetest.get_content_id("tnt:tnt_burning") - local c_gunpowder = minetest.get_content_id("tnt:gunpowder") - local c_gunpowder_burning = minetest.get_content_id("tnt:gunpowder_burning") - local c_boom = minetest.get_content_id("tnt:boom") - local c_fire = minetest.get_content_id("fire:basic_flame") for z = -radius, radius do for y = -radius, radius do @@ -189,13 +190,7 @@ local function explode(pos, radius) p.x = pos.x + x p.y = pos.y + y p.z = pos.z + z - if cid == c_tnt or cid == c_gunpowder then - burn(p) - elseif cid ~= c_tnt_burning and - cid ~= c_gunpowder_burning and - cid ~= c_air and - cid ~= c_fire and - cid ~= c_boom then + if cid ~= c_air then destroy(drops, p, cid) end end @@ -231,6 +226,9 @@ minetest.register_node("tnt:tnt", { minetest.get_node_timer(pos):start(4) end end, + on_blast = function(pos, intensity) + burn(pos) + end, mesecons = {effector = {action_on = boom}}, }) @@ -250,6 +248,7 @@ minetest.register_node("tnt:tnt_burning", { drop = "", sounds = default.node_sound_wood_defaults(), on_timer = boom, + on_blast = function() end, }) minetest.register_node("tnt:boom", { @@ -262,6 +261,7 @@ minetest.register_node("tnt:boom", { on_timer = function(pos, elapsed) minetest.remove_node(pos) end, + on_blast = function() end, }) minetest.register_node("tnt:gunpowder", { @@ -285,6 +285,9 @@ minetest.register_node("tnt:gunpowder", { burn(pos) end end, + on_blast = function(pos, intensity) + burn(pos) + end, }) minetest.register_node("tnt:gunpowder_burning", { @@ -324,7 +327,8 @@ minetest.register_node("tnt:gunpowder_burning", { end end minetest.remove_node(pos) - end + end, + on_blast = function() end, }) minetest.register_abm({ From 65bf238f1e2b46c2f6d33f1cd730b19929f1a104 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 7 Mar 2015 17:25:55 +0100 Subject: [PATCH 2/6] Add some comments regarding on_blast --- mods/doors/init.lua | 1 + mods/fire/init.lua | 1 + mods/tnt/init.lua | 3 +++ 3 files changed, 5 insertions(+) diff --git a/mods/doors/init.lua b/mods/doors/init.lua index 2b326b07..902e1cf5 100644 --- a/mods/doors/init.lua +++ b/mods/doors/init.lua @@ -26,6 +26,7 @@ function doors.register_door(name, def) def.sound_open_door = "doors_door_open" end if def.only_placer_can_open then + -- unaffected by explosions def.on_blast = function() end end diff --git a/mods/fire/init.lua b/mods/fire/init.lua index c07ad35f..89488726 100644 --- a/mods/fire/init.lua +++ b/mods/fire/init.lua @@ -25,6 +25,7 @@ minetest.register_node("fire:basic_flame", { minetest.after(0, fire.on_flame_remove_at, pos) end, + -- unaffected by explosions on_blast = function() end, }) diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index 94925b75..c7785002 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -248,6 +248,7 @@ minetest.register_node("tnt:tnt_burning", { drop = "", sounds = default.node_sound_wood_defaults(), on_timer = boom, + -- unaffected by explosions on_blast = function() end, }) @@ -261,6 +262,7 @@ minetest.register_node("tnt:boom", { on_timer = function(pos, elapsed) minetest.remove_node(pos) end, + -- unaffected by explosions on_blast = function() end, }) @@ -328,6 +330,7 @@ minetest.register_node("tnt:gunpowder_burning", { end minetest.remove_node(pos) end, + -- unaffected by explosions on_blast = function() end, }) From c4b8a75ff06257b70504e5e0beab9c3f92852d55 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 8 Mar 2015 10:30:44 +0100 Subject: [PATCH 3/6] Use cid_data cache instead of direct lookup in TNT mod --- mods/tnt/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index c7785002..f042a892 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -82,7 +82,7 @@ local function destroy(drops, pos, cid) if def and def.flammable then minetest.set_node(pos, fire_node) else - local nodename = minetest.get_node(pos).name + local nodename = cid_data[cid].name local on_blast = minetest.registered_nodes[nodename].on_blast if on_blast ~= nil then on_blast(pos, 1) From dfdb8b79c6776be9a6c577ef6dbc66b4a2f2a8a6 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 8 Mar 2015 10:33:29 +0100 Subject: [PATCH 4/6] Clean up cid_data stuff in TNT mod --- mods/tnt/init.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index f042a892..831478b5 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -23,6 +23,7 @@ minetest.after(0, function() name = name, drops = def.drops, flammable = def.groups.flammable, + on_blast = def.on_blast, } end end) @@ -82,8 +83,8 @@ local function destroy(drops, pos, cid) if def and def.flammable then minetest.set_node(pos, fire_node) else - local nodename = cid_data[cid].name - local on_blast = minetest.registered_nodes[nodename].on_blast + local nodename = def.name + local on_blast = def.on_blast if on_blast ~= nil then on_blast(pos, 1) return From 52aaf851942a0f668bd840293bb40472972ef12f Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 8 Mar 2015 10:37:45 +0100 Subject: [PATCH 5/6] More TNT cleanup --- mods/tnt/init.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/mods/tnt/init.lua b/mods/tnt/init.lua index 831478b5..dfe0a230 100644 --- a/mods/tnt/init.lua +++ b/mods/tnt/init.lua @@ -83,7 +83,6 @@ local function destroy(drops, pos, cid) if def and def.flammable then minetest.set_node(pos, fire_node) else - local nodename = def.name local on_blast = def.on_blast if on_blast ~= nil then on_blast(pos, 1) From 0c6fdbdd05ced11649cc2d20665819e6a46d9cd4 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 9 May 2015 17:31:31 +0200 Subject: [PATCH 6/6] Destroy doors completely on on_blast event --- mods/doors/init.lua | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/mods/doors/init.lua b/mods/doors/init.lua index 902e1cf5..74c7eec6 100644 --- a/mods/doors/init.lua +++ b/mods/doors/init.lua @@ -25,10 +25,6 @@ function doors.register_door(name, def) if not def.sound_open_door then def.sound_open_door = "doors_door_open" end - if def.only_placer_can_open then - -- unaffected by explosions - def.on_blast = function() end - end minetest.register_craftitem(name, { @@ -112,6 +108,33 @@ function doors.register_door(name, def) end end + local function check_and_blast(pos, name) + local node = minetest.get_node(pos) + if node.name == name then + minetest.remove_node(pos) + end + end + + local function make_on_blast(base_name, door_type, other_door_type) + if def.only_placer_can_open then + return function() end + else + if door_type == "_b_1" or door_type == "_b_2" then + return function(pos, intensity) + check_and_blast(pos, name..door_type) + pos.y = pos.y + 1 + check_and_blast(pos, name..other_door_type) + end + elseif door_type == "_t_1" or door_type == "_t_2" then + return function(pos, intensity) + check_and_blast(pos, name..door_type) + pos.y = pos.y - 1 + check_and_blast(pos, name..other_door_type) + end + end + end + end + local function on_rightclick(pos, dir, check_name, replace, replace_dir, params) pos.y = pos.y+dir if not minetest.get_node(pos).name == check_name then @@ -178,7 +201,7 @@ function doors.register_door(name, def) can_dig = check_player_priv, sounds = def.sounds, sunlight_propagates = def.sunlight, - on_blast = def.on_blast, + on_blast = make_on_blast(name, "_b_1", "_t_1") }) minetest.register_node(name.."_t_1", { @@ -211,7 +234,7 @@ function doors.register_door(name, def) can_dig = check_player_priv, sounds = def.sounds, sunlight_propagates = def.sunlight, - on_blast = def.on_blast, + on_blast = make_on_blast(name, "_t_1", "_b_1") }) minetest.register_node(name.."_b_2", { @@ -244,7 +267,7 @@ function doors.register_door(name, def) can_dig = check_player_priv, sounds = def.sounds, sunlight_propagates = def.sunlight, - on_blast = def.on_blast, + on_blast = make_on_blast(name, "_b_2", "_t_2") }) minetest.register_node(name.."_t_2", { @@ -277,7 +300,7 @@ function doors.register_door(name, def) can_dig = check_player_priv, sounds = def.sounds, sunlight_propagates = def.sunlight, - on_blast = def.on_blast, + on_blast = make_on_blast(name, "_t_2", "_b_2") }) end