Merge pull request #54 from fluxionary/multiblock_dig_fix

properly remove entire fermenter and reformer
This commit is contained in:
Joachim Stolberg 2020-08-23 19:15:05 +02:00 committed by GitHub
commit 1175301dc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 107 additions and 19 deletions

@ -198,20 +198,23 @@ minetest.register_node("tubelib_addons1:fermenter", {
end,
-- the fermenter needs 'on_dig' to be able to remove the upper node
on_dig = function(pos, node, puncher, pointed_thing)
on_dig = function(pos, node, player)
local pos_above = vector.add(pos, vector.new(0, 1, 0))
local player_name = player:get_player_name()
if minetest.is_protected(pos, player_name) or minetest.is_protected(pos_above, player_name) then
return
end
local meta = M(pos)
local inv = meta:get_inventory()
if inv:is_empty("dst") and inv:is_empty("src") then
minetest.node_dig(pos, node, puncher, pointed_thing)
minetest.remove_node({x=pos.x, y=pos.y+1, z=pos.z})
State:on_dig_node(pos, node, player)
tubelib.remove_node(pos)
minetest.remove_node(pos_above)
end
end,
on_dig = function(pos, node, player)
State:on_dig_node(pos, node, player)
tubelib.remove_node(pos)
end,
on_rotate = screwdriver.disallow,
on_timer = keep_running,
on_receive_fields = on_receive_fields,
@ -267,11 +270,18 @@ minetest.register_node("tubelib_addons1:fermenter_defect", {
-- the fermenter needs 'on_dig' to be able to remove the upper node
on_dig = function(pos, node, puncher, pointed_thing)
local pos_above = vector.add(pos, vector.new(0, 1, 0))
local puncher_name = puncher:get_player_name()
if minetest.is_protected(pos, puncher_name) or minetest.is_protected(pos_above, puncher_name) then
return
end
local meta = M(pos)
local inv = meta:get_inventory()
if inv:is_empty("dst") and inv:is_empty("src") then
minetest.node_dig(pos, node, puncher, pointed_thing)
minetest.remove_node({x=pos.x, y=pos.y+1, z=pos.z})
minetest.remove_node(pos_above)
end
end,

@ -22,4 +22,5 @@ dofile(minetest.get_modpath("tubelib_addons1") .. '/funnel.lua')
dofile(minetest.get_modpath("tubelib_addons1") .. "/pusher_fast.lua")
dofile(minetest.get_modpath("tubelib_addons1") .. "/detector.lua")
dofile(minetest.get_modpath("tubelib_addons1") .. '/chest.lua')
dofile(minetest.get_modpath("tubelib_addons1") .. '/liquidsampler.lua')
dofile(minetest.get_modpath("tubelib_addons1") .. '/liquidsampler.lua')
dofile(minetest.get_modpath("tubelib_addons1") .. '/lbms.lua')

67
tubelib_addons1/lbms.lua Normal file

@ -0,0 +1,67 @@
local bottoms_by_top = {
["tubelib_addons1:fermenter_top"] = {"tubelib_addons1:fermenter", "tubelib_addons1:fermenter_defect"},
["tubelib_addons1:reformer_top"] = {"tubelib_addons1:reformer", "tubelib_addons1:reformer_defect"},
}
local top_by_bottom = {
["tubelib_addons1:fermenter"] = "tubelib_addons1:fermenter_top",
["tubelib_addons1:fermenter_defect"] = "tubelib_addons1:fermenter_top",
["tubelib_addons1:reformer"] = "tubelib_addons1:reformer_top",
["tubelib_addons1:reformer_defect"] = "tubelib_addons1:reformer_top",
}
-- remove tops of multiblocks which aren't over the bottom; happens due to bugs or worldedit
minetest.register_lbm({
label = "Remove detached tops of multiblocks",
name = "tubelib_addons1:remove_detached_tops",
nodenames = {
"tubelib_addons1:fermenter_top",
"tubelib_addons1:reformer_top",
},
run_at_every_load = true,
action = function(pos, node)
local bottoms = bottoms_by_top[node.name]
local pos_under = vector.subtract(pos, vector.new(0, 1, 0))
local node_under = minetest.get_node_or_nil(pos_under)
if not node_under then
-- not loaded
return
end
local node_under_name = node_under.name
for _, bottom in ipairs(bottoms) do
if node_under_name == bottom then
-- has an acceptable bottom
return
end
end
minetest.remove_node(pos)
end
})
-- fix multiblocks with missing tops; happens due to bugs or worldedit
minetest.register_lbm({
label = "Fix missing tops of multiblocks",
name = "tubelib_addons1:fix_missing_tops",
nodenames = {
"tubelib_addons1:fermenter",
"tubelib_addons1:fermenter_defect",
"tubelib_addons1:reformer",
"tubelib_addons1:reformer_defect",
},
run_at_every_load = true,
action = function(pos, node)
local pos_above = vector.add(pos, vector.new(0, 1, 0))
local node_above = minetest.get_node(pos_above)
if node_above.name ~= "air" then
return
end
local top = top_by_bottom[node.name]
minetest.add_node(pos_above, {name=top, param2=node.param2})
end
})

@ -194,20 +194,23 @@ minetest.register_node("tubelib_addons1:reformer", {
end,
-- the reformer needs 'on_dig' to be able to remove the upper node
on_dig = function(pos, node, puncher, pointed_thing)
on_dig = function(pos, node, puncher)
local pos_above = vector.add(pos, vector.new(0, 1, 0))
local player_name = puncher:get_player_name()
if minetest.is_protected(pos, player_name) or minetest.is_protected(pos_above, player_name) then
return
end
local meta = M(pos)
local inv = meta:get_inventory()
if inv:is_empty("dst") and inv:is_empty("src") then
minetest.node_dig(pos, node, puncher, pointed_thing)
minetest.remove_node({x=pos.x, y=pos.y+1, z=pos.z})
State:on_dig_node(pos, node, puncher)
tubelib.remove_node(pos)
minetest.remove_node(pos_above)
end
end,
on_dig = function(pos, node, player)
State:on_dig_node(pos, node, player)
tubelib.remove_node(pos)
end,
on_rotate = screwdriver.disallow,
on_timer = keep_running,
on_receive_fields = on_receive_fields,
@ -263,11 +266,18 @@ minetest.register_node("tubelib_addons1:reformer_defect", {
-- the reformer needs 'on_dig' to be able to remove the upper node
on_dig = function(pos, node, puncher, pointed_thing)
local pos_above = vector.add(pos, vector.new(0, 1, 0))
local puncher_name = puncher:get_player_name()
if minetest.is_protected(pos, puncher_name) or minetest.is_protected(pos_above, puncher_name) then
return
end
local meta = M(pos)
local inv = meta:get_inventory()
if inv:is_empty("dst") and inv:is_empty("src") then
minetest.node_dig(pos, node, puncher, pointed_thing)
minetest.remove_node({x=pos.x, y=pos.y+1, z=pos.z})
minetest.remove_node(pos_above)
end
end,