1
0
Fork 0

Improve dig_node simulation and fix duplication

This commit is contained in:
seventeenthShulker 2023-07-02 13:08:59 +02:00
parent 918b8eee38
commit 058684f17f
2 changed files with 17 additions and 9 deletions

View File

@ -246,6 +246,15 @@ function mesecon.mergetable(source, dest)
return rval return rval
end 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) function mesecon.register_node(name, spec_common, spec_off, spec_on)
spec_common.drop = spec_common.drop or name .. "_off" spec_common.drop = spec_common.drop or name .. "_off"
spec_common.on_blast = spec_common.on_blast or mesecon.on_blastnode spec_common.on_blast = spec_common.on_blast or mesecon.on_blastnode

View File

@ -259,7 +259,7 @@ function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, player_name,
end end
local all_nodes = nodes 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 if are_protected(all_nodes, player_name) then
return return
end 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() n.meta = minetest.get_meta(n.pos):to_table()
local is_dropper = mesecon.is_mvps_dropper(n.node, movedir, all_nodes, id) local is_dropper = mesecon.is_mvps_dropper(n.node, movedir, all_nodes, id)
if is_dropper then if is_dropper then
-- minetest.dig_node has been shown to be buggy (https://git.minetest.land/MineClone2/MineClone2/issues/3547) -- if current node has already been destroyed (e.g. chain reaction of sugar cane breaking), skip it
if minetest.get_item_group(n.node.name, "dig_immediate") == 3 then if minetest.get_node(n.pos).name == n.node.name then
-- should dig as normal -- simulate dig_node using handle_node_drops
minetest.dig_node(n.pos)
else
-- simulate dig_node because nothing drops otherwise
local drops = minetest.get_node_drops(n.node.name, "") local drops = minetest.get_node_drops(n.node.name, "")
local counted_drops = {}
minetest.remove_node(n.pos) minetest.remove_node(n.pos)
for _, callback in pairs(minetest.registered_on_dignodes) do for _, callback in pairs(minetest.registered_on_dignodes) do
callback(n.pos, n) 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 if type(item) ~= "string" then
item = item:get_name() .. item:get_count() item = item:get_name() .. item:get_count()
end end
minetest.add_item(n.pos, item) table.insert(counted_drops, item)
end end
minetest.handle_node_drops(n.pos, counted_drops)
end end
else else
minetest.remove_node(n.pos) minetest.remove_node(n.pos)