From 058684f17f8ae824dda9ced84224fc3002b824d6 Mon Sep 17 00:00:00 2001 From: seventeenthShulker Date: Sun, 2 Jul 2023 13:08:59 +0200 Subject: [PATCH] Improve dig_node simulation and fix duplication --- mods/ITEMS/REDSTONE/mesecons/util.lua | 9 +++++++++ mods/ITEMS/REDSTONE/mesecons_mvps/init.lua | 17 ++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/mods/ITEMS/REDSTONE/mesecons/util.lua b/mods/ITEMS/REDSTONE/mesecons/util.lua index b6602526a..12dbc0240 100644 --- a/mods/ITEMS/REDSTONE/mesecons/util.lua +++ b/mods/ITEMS/REDSTONE/mesecons/util.lua @@ -246,6 +246,15 @@ function mesecon.mergetable(source, dest) return rval end +-- +function mesecon.join_table(t1, t2) + local rval = mesecon.tablecopy(t2) + for i, v in ipairs(t1) do + table.insert(rval, mesecon.tablecopy(v)) + end + return rval +end + function mesecon.register_node(name, spec_common, spec_off, spec_on) spec_common.drop = spec_common.drop or name .. "_off" spec_common.on_blast = spec_common.on_blast or mesecon.on_blastnode diff --git a/mods/ITEMS/REDSTONE/mesecons_mvps/init.lua b/mods/ITEMS/REDSTONE/mesecons_mvps/init.lua index 814c5d80d..f282f4dca 100644 --- a/mods/ITEMS/REDSTONE/mesecons_mvps/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_mvps/init.lua @@ -234,7 +234,7 @@ function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, player_name, end if not nodes then return end - + local newpos={} -- check node availability to push/pull into, and fill newpos[i] for i in ipairs(nodes) do @@ -259,7 +259,7 @@ function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, player_name, end local all_nodes = nodes - if dig_nodes and #dig_nodes > 0 then all_nodes = mesecon.mergetable(dig_nodes, nodes) end + if dig_nodes and #dig_nodes > 0 then all_nodes = mesecon.join_table(dig_nodes, nodes) end if are_protected(all_nodes, player_name) then return end @@ -270,13 +270,11 @@ function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, player_name, n.meta = minetest.get_meta(n.pos):to_table() local is_dropper = mesecon.is_mvps_dropper(n.node, movedir, all_nodes, id) if is_dropper then - -- minetest.dig_node has been shown to be buggy (https://git.minetest.land/MineClone2/MineClone2/issues/3547) - if minetest.get_item_group(n.node.name, "dig_immediate") == 3 then - -- should dig as normal - minetest.dig_node(n.pos) - else - -- simulate dig_node because nothing drops otherwise + -- if current node has already been destroyed (e.g. chain reaction of sugar cane breaking), skip it + if minetest.get_node(n.pos).name == n.node.name then + -- simulate dig_node using handle_node_drops local drops = minetest.get_node_drops(n.node.name, "") + local counted_drops = {} minetest.remove_node(n.pos) for _, callback in pairs(minetest.registered_on_dignodes) do callback(n.pos, n) @@ -285,8 +283,9 @@ function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, player_name, if type(item) ~= "string" then item = item:get_name() .. item:get_count() end - minetest.add_item(n.pos, item) + table.insert(counted_drops, item) end + minetest.handle_node_drops(n.pos, counted_drops) end else minetest.remove_node(n.pos)