From 898715edf7513b3cb74995074fe344edc7be9d80 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Fri, 15 Apr 2016 20:13:53 +0100 Subject: [PATCH 1/3] Added on_blast to default chest Added on_blast function to default chest so that tnt explosions or mob blasts do not destroy it. Also tidied some code. --- mods/default/nodes.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index 1550e141..b806d88b 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -1463,16 +1463,17 @@ minetest.register_node("default:chest", { minetest.log("action", player:get_player_name() .. " moves stuff in chest at " .. minetest.pos_to_string(pos)) end, - on_metadata_inventory_put = function(pos, listname, index, stack, player) + on_metadata_inventory_put = function(pos, listname, index, stack, player) minetest.log("action", player:get_player_name() .. " moves " .. stack:get_name() .. " to chest at " .. minetest.pos_to_string(pos)) end, - on_metadata_inventory_take = function(pos, listname, index, stack, player) + on_metadata_inventory_take = function(pos, listname, index, stack, player) minetest.log("action", player:get_player_name() .. " takes " .. stack:get_name() .. " from chest at " .. minetest.pos_to_string(pos)) end, + on_blast = function() end, }) minetest.register_node("default:chest_locked", { @@ -1511,26 +1512,26 @@ minetest.register_node("default:chest_locked", { end return count end, - allow_metadata_inventory_put = function(pos, listname, index, stack, player) + allow_metadata_inventory_put = function(pos, listname, index, stack, player) local meta = minetest.get_meta(pos) if not has_locked_chest_privilege(meta, player) then return 0 end return stack:get_count() end, - allow_metadata_inventory_take = function(pos, listname, index, stack, player) + allow_metadata_inventory_take = function(pos, listname, index, stack, player) local meta = minetest.get_meta(pos) if not has_locked_chest_privilege(meta, player) then return 0 end return stack:get_count() end, - on_metadata_inventory_put = function(pos, listname, index, stack, player) + on_metadata_inventory_put = function(pos, listname, index, stack, player) minetest.log("action", player:get_player_name() .. " moves " .. stack:get_name() .. " to locked chest at " .. minetest.pos_to_string(pos)) end, - on_metadata_inventory_take = function(pos, listname, index, stack, player) + on_metadata_inventory_take = function(pos, listname, index, stack, player) minetest.log("action", player:get_player_name() .. " takes " .. stack:get_name() .. " from locked chest at " .. minetest.pos_to_string(pos)) From 750da16b4b357655842eb30b7a61dd64e7801e6c Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Fri, 15 Apr 2016 20:25:44 +0100 Subject: [PATCH 2/3] chests drop items inside when blown up Chests will drop items inside when blown up --- mods/default/nodes.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index b806d88b..3b1132be 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -1473,7 +1473,21 @@ minetest.register_node("default:chest", { " takes " .. stack:get_name() .. " from chest at " .. minetest.pos_to_string(pos)) end, - on_blast = function() end, + on_blast = function(pos) + local inv = minetest.get_meta(pos):get_inventory() + for i = 1, inv:get_size("main") do + local m_stack = inv:get_stack("main", i) + local obj = minetest.add_item(pos, m_stack) + if obj then + obj:setvelocity({ + x = math.random(-10, 10) / 9, + y = 3, + z = math.random(-10, 10) / 9 + }) + end + end + minetest.remove_node(pos) + end, }) minetest.register_node("default:chest_locked", { From 749dca04ef76115e7fbadafd11e54c89358f9c75 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Fri, 15 Apr 2016 20:36:25 +0100 Subject: [PATCH 3/3] added minetest.after to account for lag added minetest.after function to account for lag as it will not drop items without it. --- mods/default/nodes.lua | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/mods/default/nodes.lua b/mods/default/nodes.lua index 3b1132be..716ca4fa 100644 --- a/mods/default/nodes.lua +++ b/mods/default/nodes.lua @@ -1474,19 +1474,21 @@ minetest.register_node("default:chest", { " from chest at " .. minetest.pos_to_string(pos)) end, on_blast = function(pos) - local inv = minetest.get_meta(pos):get_inventory() - for i = 1, inv:get_size("main") do - local m_stack = inv:get_stack("main", i) - local obj = minetest.add_item(pos, m_stack) - if obj then - obj:setvelocity({ - x = math.random(-10, 10) / 9, - y = 3, - z = math.random(-10, 10) / 9 - }) + minetest.after(0.1, function() + local inv = minetest.get_meta(pos):get_inventory() + for i = 1, inv:get_size("main") do + local m_stack = inv:get_stack("main", i) + local obj = minetest.add_item(pos, m_stack) + if obj then + obj:setvelocity({ + x = math.random(-10, 10) / 9, + y = 3, + z = math.random(-10, 10) / 9 + }) + end end - end - minetest.remove_node(pos) + minetest.remove_node(pos) + end) end, })