diff --git a/smartline/button.lua b/smartline/button.lua index d3afc31..1b55e69 100644 --- a/smartline/button.lua +++ b/smartline/button.lua @@ -135,6 +135,10 @@ minetest.register_node("smartline:button", { end end, + after_dig_node = function(pos) + tubelib.remove_node(pos) + end, + paramtype = "light", sunlight_propagates = true, paramtype2 = "facedir", @@ -174,6 +178,10 @@ minetest.register_node("smartline:button_active", { on_timer = switch_off, + after_dig_node = function(pos) + tubelib.remove_node(pos) + end, + paramtype = "light", sunlight_propagates = true, paramtype2 = "facedir", diff --git a/smartline/display.lua b/smartline/display.lua index 2519d07..6dfe3cf 100644 --- a/smartline/display.lua +++ b/smartline/display.lua @@ -64,6 +64,10 @@ minetest.register_node("smartline:display", { lcdlib.update_entities(pos) end, + after_dig_node = function(pos) + tubelib.remove_node(pos) + end, + on_timer = on_timer, on_place = lcdlib.on_place, on_construct = lcdlib.on_construct, diff --git a/techpack_warehouse/box_copper.lua b/techpack_warehouse/box_copper.lua index 1bb0f4f..87c9474 100644 --- a/techpack_warehouse/box_copper.lua +++ b/techpack_warehouse/box_copper.lua @@ -44,8 +44,11 @@ minetest.register_node(NODE_NAME, { on_timer = function(pos,elapsed) return wh.on_timer(Box, pos,elapsed) end, - on_dig = function(pos, node, puncher, pointed_thing) - wh.on_dig(Box, pos, node, puncher, pointed_thing) + can_dig = function(pos) + return wh.can_dig(Box, pos) + end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + wh.after_dig_node(Box, pos, oldnode, oldmetadata, digger) end, allow_metadata_inventory_put = function(pos, listname, index, stack, player) return wh.allow_metadata_inventory_put(Box, pos, listname, index, stack, player) @@ -55,6 +58,7 @@ minetest.register_node(NODE_NAME, { allow_metadata_inventory_move = wh.allow_metadata_inventory_move, on_rotate = screwdriver.disallow, + drop = "", paramtype = "light", sunlight_propagates = true, paramtype2 = "facedir", @@ -100,8 +104,11 @@ minetest.register_node(NODE_NAME.."_defect", { wh.after_place_node(Box, pos, placer, itemstack) Box.State:defect(pos, M(pos)) end, - on_dig = function(pos, node, puncher, pointed_thing) - wh.on_dig(Box, pos, node, puncher, pointed_thing) + can_dig = function(pos) + return wh.can_dig(Box, pos) + end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + wh.after_dig_node(Box, pos, oldnode, oldmetadata, digger) end, allow_metadata_inventory_put = function(pos, listname, index, stack, player) return wh.allow_metadata_inventory_put(Box, pos, listname, index, stack, player) @@ -125,10 +132,11 @@ tubelib.register_node(NODE_NAME, local meta = M(pos) meta:set_string("push_dir", side) local num = wh.numbers_to_shift(Box, meta, item) - if num then + if num > 0 then item:set_count(num) return tubelib.put_item(meta, "shift", item) end + return true end, on_pull_stack = function(pos, side) return tubelib.get_stack(M(pos), "main") diff --git a/techpack_warehouse/box_gold.lua b/techpack_warehouse/box_gold.lua index 80c8c15..00b68db 100644 --- a/techpack_warehouse/box_gold.lua +++ b/techpack_warehouse/box_gold.lua @@ -44,8 +44,11 @@ minetest.register_node(NODE_NAME, { on_timer = function(pos,elapsed) return wh.on_timer(Box, pos,elapsed) end, - on_dig = function(pos, node, puncher, pointed_thing) - wh.on_dig(Box, pos, node, puncher, pointed_thing) + can_dig = function(pos) + return wh.can_dig(Box, pos) + end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + wh.after_dig_node(Box, pos, oldnode, oldmetadata, digger) end, allow_metadata_inventory_put = function(pos, listname, index, stack, player) return wh.allow_metadata_inventory_put(Box, pos, listname, index, stack, player) @@ -55,6 +58,7 @@ minetest.register_node(NODE_NAME, { allow_metadata_inventory_move = wh.allow_metadata_inventory_move, on_rotate = screwdriver.disallow, + drop = "", paramtype = "light", sunlight_propagates = true, paramtype2 = "facedir", @@ -100,8 +104,11 @@ minetest.register_node(NODE_NAME.."_defect", { wh.after_place_node(Box, pos, placer, itemstack) Box.State:defect(pos, M(pos)) end, - on_dig = function(pos, node, puncher, pointed_thing) - wh.on_dig(Box, pos, node, puncher, pointed_thing) + can_dig = function(pos) + return wh.can_dig(Box, pos) + end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + wh.after_dig_node(Box, pos, oldnode, oldmetadata, digger) end, allow_metadata_inventory_put = function(pos, listname, index, stack, player) return wh.allow_metadata_inventory_put(Box, pos, listname, index, stack, player) @@ -125,10 +132,11 @@ tubelib.register_node(NODE_NAME, local meta = M(pos) meta:set_string("push_dir", side) local num = wh.numbers_to_shift(Box, meta, item) - if num then + if num > 0 then item:set_count(num) return tubelib.put_item(meta, "shift", item) end + return true end, on_pull_stack = function(pos, side) return tubelib.get_stack(M(pos), "main") diff --git a/techpack_warehouse/box_steel.lua b/techpack_warehouse/box_steel.lua index c4b91f4..6ce0d12 100644 --- a/techpack_warehouse/box_steel.lua +++ b/techpack_warehouse/box_steel.lua @@ -44,8 +44,11 @@ minetest.register_node(NODE_NAME, { on_timer = function(pos,elapsed) return wh.on_timer(Box, pos,elapsed) end, - on_dig = function(pos, node, puncher, pointed_thing) - wh.on_dig(Box, pos, node, puncher, pointed_thing) + can_dig = function(pos) + return wh.can_dig(Box, pos) + end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + wh.after_dig_node(Box, pos, oldnode, oldmetadata, digger) end, allow_metadata_inventory_put = function(pos, listname, index, stack, player) return wh.allow_metadata_inventory_put(Box, pos, listname, index, stack, player) @@ -55,6 +58,7 @@ minetest.register_node(NODE_NAME, { allow_metadata_inventory_move = wh.allow_metadata_inventory_move, on_rotate = screwdriver.disallow, + drop = "", paramtype = "light", sunlight_propagates = true, paramtype2 = "facedir", @@ -100,8 +104,11 @@ minetest.register_node(NODE_NAME.."_defect", { wh.after_place_node(Box, pos, placer, itemstack) Box.State:defect(pos, M(pos)) end, - on_dig = function(pos, node, puncher, pointed_thing) - wh.on_dig(Box, pos, node, puncher, pointed_thing) + can_dig = function(pos) + return wh.can_dig(Box, pos) + end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + wh.after_dig_node(Box, pos, oldnode, oldmetadata, digger) end, allow_metadata_inventory_put = function(pos, listname, index, stack, player) return wh.allow_metadata_inventory_put(Box, pos, listname, index, stack, player) @@ -125,10 +132,11 @@ tubelib.register_node(NODE_NAME, local meta = M(pos) meta:set_string("push_dir", side) local num = wh.numbers_to_shift(Box, meta, item) - if num then + if num > 0 then item:set_count(num) return tubelib.put_item(meta, "shift", item) end + return true end, on_pull_stack = function(pos, side) return tubelib.get_stack(M(pos), "main") diff --git a/techpack_warehouse/common.lua b/techpack_warehouse/common.lua index c1b0503..dbd6718 100644 --- a/techpack_warehouse/common.lua +++ b/techpack_warehouse/common.lua @@ -147,7 +147,7 @@ end function techpack_warehouse.numbers_to_shift(self, meta, item) -- check cache - local number = meta:get_string("number") + local number = meta:get_string("tubelib_number") local item_name = item:get_name() if not Cache[number] then local inv = meta:get_inventory() @@ -191,7 +191,7 @@ function techpack_warehouse.allow_metadata_inventory_put(self, pos, listname, in if listname == "input" and item_name == stack:get_name() then return math.min(stack:get_count(), self.inv_size - main_stack:get_count()) elseif listname == "filter" and item_name == main_stack:get_name() then - local number = M(pos):get_string("number") + local number = M(pos):get_string("tubelib_number") Cache[number] = nil return 1 elseif listname == "shift" then @@ -202,7 +202,7 @@ end function techpack_warehouse.on_metadata_inventory_put(pos, listname, index, stack, player) if listname == "input" then - local number = M(pos):get_string("number") + local number = M(pos):get_string("tubelib_number") Cache[number] = nil minetest.after(0.5, move_to_main, pos, index) end @@ -213,7 +213,7 @@ function techpack_warehouse.allow_metadata_inventory_take(pos, listname, index, return 0 end if listname == "main" then - local number = M(pos):get_string("number") + local number = M(pos):get_string("tubelib_number") Cache[number] = nil local inv = M(pos):get_inventory() local list = inv:get_list("main") @@ -224,11 +224,11 @@ function techpack_warehouse.allow_metadata_inventory_take(pos, listname, index, return num end elseif listname == "filter" then - local number = M(pos):get_string("number") + local number = M(pos):get_string("tubelib_number") Cache[number] = nil return 1 elseif listname == "shift" then - local number = M(pos):get_string("number") + local number = M(pos):get_string("tubelib_number") Cache[number] = nil return stack:get_count() end @@ -243,7 +243,7 @@ function techpack_warehouse.on_receive_fields(self, pos, formname, fields, playe if minetest.is_protected(pos, player:get_player_name()) then return end - local number = M(pos):get_string("number") + local number = M(pos):get_string("tubelib_number") Cache[number] = nil self.State:state_button_event(pos, fields) end @@ -264,7 +264,7 @@ function techpack_warehouse.on_timer(self, pos, elapsed) local meta = M(pos) local inv = meta:get_inventory() if not inv:is_empty("shift") then - local number = meta:get_string("number") + --local number = meta:get_string("tubelib_number") local player_name = meta:get_string("player_name") local offs = meta:get_int("offs") local push_dir = meta:get_string("push_dir") @@ -295,10 +295,14 @@ function techpack_warehouse.on_timer(self, pos, elapsed) return self.State:is_active(meta) end -function techpack_warehouse.on_dig(self, pos, node, puncher, pointed_thing) +function techpack_warehouse.can_dig(self, pos) local inv = M(pos):get_inventory() - if inv:is_empty("main") and inv:is_empty("shift") then - minetest.node_dig(pos, node, puncher, pointed_thing) - tubelib.remove_node(pos) + return inv:is_empty("main") and inv:is_empty("shift") +end + +function techpack_warehouse.after_dig_node(self, pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) + if oldnode.name == self.node_name then -- not for defect nodes + self.State:after_dig_node(pos, oldnode, oldmetadata, digger) end end diff --git a/tubelib/blackhole.lua b/tubelib/blackhole.lua index 77394a2..cc890ae 100644 --- a/tubelib/blackhole.lua +++ b/tubelib/blackhole.lua @@ -88,6 +88,7 @@ tubelib.register_node("tubelib:blackhole", {}, { on_recv_message = function(pos, topic, payload) local node = minetest.get_node(pos) if topic == "state" then + local meta = minetest.get_meta(pos) return meta:get_int("disappeared") else return "not supported" diff --git a/tubelib/command.lua b/tubelib/command.lua index f60b077..42c2727 100644 --- a/tubelib/command.lua +++ b/tubelib/command.lua @@ -151,6 +151,13 @@ local function get_dest_node(pos, side) return spos, in_side, Name2Name[node.name] or node.name end +local function item_handling_node(name) + local node_def = name and tubelib_NodeDef[name] + if node_def then + return node_def.on_pull_item or node_def.on_push_item or node_def.is_pusher + end +end + ------------------------------------------------------------------- -- API helper functions ------------------------------------------------------------------- @@ -219,6 +226,11 @@ end -- Function determines and returns the node position number, -- needed for message communication. function tubelib.add_node(pos, name) + print("tubelib.add_node", S(pos)) + if item_handling_node(name) then + print("Tube:after_place_node") + Tube:after_place_node(pos) + end -- store position local number = get_number(pos) Number2Pos[number] = { @@ -230,14 +242,21 @@ end -- Function removes the node from the tubelib lists. function tubelib.remove_node(pos) + print("tubelib.remove_node", S(pos)) local number = get_number(pos) + local name if Number2Pos[number] then + name = Number2Pos[number].name Number2Pos[number] = { pos = pos, name = nil, time = minetest.get_day_count() -- used for reservation timeout } end + if item_handling_node(name) then + print("Tube:after_dig_node") + Tube:after_dig_node(pos) + end end diff --git a/tubelib/distributor.lua b/tubelib/distributor.lua index 547ae6a..21d4537 100644 --- a/tubelib/distributor.lua +++ b/tubelib/distributor.lua @@ -345,19 +345,16 @@ minetest.register_node("tubelib:distributor", { on_receive_fields = on_receive_fields, - on_dig = function(pos, node, puncher, pointed_thing) - if minetest.is_protected(pos, puncher:get_player_name()) then - return - end - local meta = M(pos) - local inv = meta:get_inventory() - if inv:is_empty("src") then - minetest.node_dig(pos, node, puncher, pointed_thing) - tubelib.remove_node(pos) -- <<=== tubelib + can_dig = function(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false end + local inv = M(pos):get_inventory() + return inv:is_empty("src") end, after_dig_node = function(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) -- <<=== tubelib State:after_dig_node(pos, oldnode, oldmetadata, digger) end, @@ -448,6 +445,18 @@ minetest.register_node("tubelib:distributor_defect", { on_receive_fields = on_receive_fields, + can_dig = function(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false + end + local inv = M(pos):get_inventory() + return inv:is_empty("src") + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) -- <<=== tubelib + end, + allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_take = allow_metadata_inventory_take, allow_metadata_inventory_move = allow_metadata_inventory_move, diff --git a/tubelib/repairkit.lua b/tubelib/repairkit.lua index 52704d0..4aba31e 100644 --- a/tubelib/repairkit.lua +++ b/tubelib/repairkit.lua @@ -46,6 +46,7 @@ local function read_state(itemstack, user, pointed_thing) local counter = tubelib.send_request(number, "counter", nil) local aging = tubelib.send_request(number, "aging", nil) if state and counter and aging then + if type(counter) ~= "number" then counter = "unknown" end minetest.chat_send_player(user:get_player_name(), "[Tubelib] state ="..state..", counter = "..counter..", aging = "..aging) end end diff --git a/tubelib_addons1/autocrafter.lua b/tubelib_addons1/autocrafter.lua index 73b8b06..ce6c305 100644 --- a/tubelib_addons1/autocrafter.lua +++ b/tubelib_addons1/autocrafter.lua @@ -301,16 +301,17 @@ minetest.register_node("tubelib_addons1:autocrafter", { inv:set_size("output", 1) end, - on_dig = function(pos, node, puncher, pointed_thing) - local inv = M(pos):get_inventory() - if inv:is_empty("dst") and inv:is_empty("src") then - minetest.node_dig(pos, node, puncher, pointed_thing) - tubelib.remove_node(pos) - autocrafterCache[minetest.hash_node_position(pos)] = nil + can_dig = function(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false end + local inv = M(pos):get_inventory() + return inv:is_empty("dst") and inv:is_empty("src") end, after_dig_node = function(pos, oldnode, oldmetadata, digger) + autocrafterCache[minetest.hash_node_position(pos)] = nil + tubelib.remove_node(pos) State:after_dig_node(pos, oldnode, oldmetadata, digger) end, @@ -385,13 +386,17 @@ minetest.register_node("tubelib_addons1:autocrafter_defect", { State:defect(pos, meta) end, - on_dig = function(pos, node, puncher, pointed_thing) - local inv = M(pos):get_inventory() - if inv:is_empty("dst") and inv:is_empty("src") then - minetest.node_dig(pos, node, puncher, pointed_thing) - tubelib.remove_node(pos) - autocrafterCache[minetest.hash_node_position(pos)] = nil + can_dig = function(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false end + local inv = M(pos):get_inventory() + return inv:is_empty("dst") and inv:is_empty("src") + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + autocrafterCache[minetest.hash_node_position(pos)] = nil + tubelib.remove_node(pos) end, allow_metadata_inventory_put = allow_metadata_inventory_put, diff --git a/tubelib_addons1/chest.lua b/tubelib_addons1/chest.lua index 5344d02..c585b38 100644 --- a/tubelib_addons1/chest.lua +++ b/tubelib_addons1/chest.lua @@ -100,20 +100,18 @@ minetest.register_node("tubelib_addons1:chest", { meta:set_string("infotext", "Tubelib Protected Chest "..number) end, - can_dig = function(pos,player) + can_dig = function(pos, player) if minetest.is_protected(pos, player:get_player_name()) then return false end - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() + local inv = minetest.get_meta(pos):get_inventory() return inv:is_empty("main") end, - - on_dig = function(pos, node, puncher, pointed_thing) - minetest.node_dig(pos, node, puncher, pointed_thing) + + after_dig_node = function(pos, oldnode, oldmetadata, digger) tubelib.remove_node(pos) end, - + allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_take = allow_metadata_inventory_take, diff --git a/tubelib_addons1/detector.lua b/tubelib_addons1/detector.lua index dcf14f7..40817ee 100644 --- a/tubelib_addons1/detector.lua +++ b/tubelib_addons1/detector.lua @@ -72,6 +72,10 @@ minetest.register_node("tubelib_addons1:detector", { end end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) + end, + on_rotate = screwdriver.disallow, paramtype = "light", sunlight_propagates = true, @@ -97,6 +101,10 @@ minetest.register_node("tubelib_addons1:detector_active", { on_timer = switch_off, on_rotate = screwdriver.disallow, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) + end, + paramtype = "light", light_source = 2, sunlight_propagates = true, diff --git a/tubelib_addons1/fermenter.lua b/tubelib_addons1/fermenter.lua index 45f0974..d79e4e6 100644 --- a/tubelib_addons1/fermenter.lua +++ b/tubelib_addons1/fermenter.lua @@ -188,17 +188,18 @@ minetest.register_node("tubelib_addons1:fermenter", { State:node_init(pos, number) end, + -- the fermenter needs 'on_dig' to be able to remove the upper node on_dig = function(pos, node, puncher, pointed_thing) 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}) - tubelib.remove_node(pos) end end, - + after_dig_node = function(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) State:after_dig_node(pos, oldnode, oldmetadata, digger) end, @@ -219,7 +220,7 @@ minetest.register_node("tubelib_addons1:fermenter", { }) minetest.register_node("tubelib_addons1:fermenter_defect", { - description = "Tubelib Fermenter", + description = "Tubelib Fermenter defect", inventory_image = "tubelib_addons1_fermenter_inventory.png", tiles = { -- up, down, right, left, back, front @@ -254,15 +255,19 @@ minetest.register_node("tubelib_addons1:fermenter_defect", { State:defect(pos, M(pos)) end, + -- the fermenter needs 'on_dig' to be able to remove the upper node on_dig = function(pos, node, puncher, pointed_thing) 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}) - tubelib.remove_node(pos) end end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) + end, on_rotate = screwdriver.disallow, allow_metadata_inventory_put = allow_metadata_inventory_put, diff --git a/tubelib_addons1/funnel.lua b/tubelib_addons1/funnel.lua index ee25f2d..108f520 100644 --- a/tubelib_addons1/funnel.lua +++ b/tubelib_addons1/funnel.lua @@ -100,7 +100,7 @@ minetest.register_node("tubelib_addons1:funnel", { on_timer = scan_for_objects, on_rotate = screwdriver.disallow, - can_dig = function(pos,player) + can_dig = function(pos, player) if minetest.is_protected(pos, player:get_player_name()) then return false end @@ -109,11 +109,10 @@ minetest.register_node("tubelib_addons1:funnel", { return inv:is_empty("main") end, - on_dig = function(pos, node, puncher, pointed_thing) - minetest.node_dig(pos, node, puncher, pointed_thing) + after_dig_node = function(pos, oldnode, oldmetadata, digger) tubelib.remove_node(pos) end, - + allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_take = allow_metadata_inventory_take, diff --git a/tubelib_addons1/grinder.lua b/tubelib_addons1/grinder.lua index 0fdfaf7..2da4f7b 100644 --- a/tubelib_addons1/grinder.lua +++ b/tubelib_addons1/grinder.lua @@ -136,17 +136,17 @@ minetest.register_node("tubelib_addons1:grinder", { inv:set_size('dst', 9) end, - on_dig = function(pos, node, puncher, pointed_thing) - 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) - tubelib.remove_node(pos) + can_dig = function(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false end + local inv = M(pos):get_inventory() + return inv:is_empty("dst") and inv:is_empty("src") end, after_dig_node = function(pos, oldnode, oldmetadata, digger) State:after_dig_node(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) end, on_rotate = screwdriver.disallow, @@ -225,15 +225,18 @@ minetest.register_node("tubelib_addons1:grinder_defect", { State:defect(pos, meta) end, - on_dig = function(pos, node, puncher, pointed_thing) - 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) - tubelib.remove_node(pos) + can_dig = function(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false end + local inv = M(pos):get_inventory() + return inv:is_empty("dst") and inv:is_empty("src") end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) + end, + on_rotate = screwdriver.disallow, allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_move = allow_metadata_inventory_move, diff --git a/tubelib_addons1/harvester.lua b/tubelib_addons1/harvester.lua index 6fde659..72c0daf 100644 --- a/tubelib_addons1/harvester.lua +++ b/tubelib_addons1/harvester.lua @@ -325,20 +325,17 @@ minetest.register_node("tubelib_addons1:harvester_base", { State:node_init(pos, number) end, - on_dig = function(pos, node, puncher, pointed_thing) - if minetest.is_protected(pos, puncher:get_player_name()) then - return - end - local meta = M(pos) - local inv = meta:get_inventory() - if inv:is_empty("main") then - minetest.node_dig(pos, node, puncher, pointed_thing) - tubelib.remove_node(pos) + can_dig = function(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false end + local inv = M(pos):get_inventory() + return inv:is_empty("main") end, after_dig_node = function(pos, oldnode, oldmetadata, digger) State:after_dig_node(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) end, on_rotate = screwdriver.disallow, @@ -389,16 +386,16 @@ minetest.register_node("tubelib_addons1:harvester_defect", { State:defect(pos, meta) end, - on_dig = function(pos, node, puncher, pointed_thing) - if minetest.is_protected(pos, puncher:get_player_name()) then - return - end - local meta = M(pos) - local inv = meta:get_inventory() - if inv:is_empty("main") then - minetest.node_dig(pos, node, puncher, pointed_thing) - tubelib.remove_node(pos) + can_dig = function(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false end + local inv = M(pos):get_inventory() + return inv:is_empty("main") + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) end, on_rotate = screwdriver.disallow, diff --git a/tubelib_addons1/liquidsampler.lua b/tubelib_addons1/liquidsampler.lua index 9c25f85..c717746 100644 --- a/tubelib_addons1/liquidsampler.lua +++ b/tubelib_addons1/liquidsampler.lua @@ -137,7 +137,7 @@ minetest.register_node("tubelib_addons1:liquidsampler", { }, after_place_node = function(pos, placer) - local number = tubelib.add_node(pos, "ttubelib_addons1:liquidsampler") + local number = tubelib.add_node(pos, "tubelib_addons1:liquidsampler") State:node_init(pos, number) local meta = M(pos) local node = minetest.get_node(pos) @@ -148,17 +148,17 @@ minetest.register_node("tubelib_addons1:liquidsampler", { inv:set_size("dst", 28) end, - on_dig = function(pos, node, puncher, pointed_thing) - 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) - tubelib.remove_node(pos) + can_dig = function(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false end + local inv = M(pos):get_inventory() + return inv:is_empty("dst") and inv:is_empty("src") end, after_dig_node = function(pos, oldnode, oldmetadata, digger) State:after_dig_node(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) end, on_rotate = screwdriver.disallow, @@ -238,13 +238,16 @@ minetest.register_node("tubelib_addons1:liquidsampler_defect", { State:defect(pos, meta) end, - on_dig = function(pos, node, puncher, pointed_thing) - 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) - tubelib.remove_node(pos) + can_dig = function(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false end + local inv = M(pos):get_inventory() + return inv:is_empty("dst") and inv:is_empty("src") + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) end, on_rotate = screwdriver.disallow, diff --git a/tubelib_addons1/quarry.lua b/tubelib_addons1/quarry.lua index af4bab8..dbada08 100644 --- a/tubelib_addons1/quarry.lua +++ b/tubelib_addons1/quarry.lua @@ -304,19 +304,16 @@ minetest.register_node("tubelib_addons1:quarry", { State:node_init(pos, number) end, - on_dig = function(pos, node, puncher, pointed_thing) - if minetest.is_protected(pos, puncher:get_player_name()) then - return - end - local meta = M(pos) - local inv = meta:get_inventory() - if inv:is_empty("main") then - minetest.node_dig(pos, node, puncher, pointed_thing) - tubelib.remove_node(pos) + can_dig = function(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false end + local inv = M(pos):get_inventory() + return inv:is_empty("main") end, after_dig_node = function(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) State:after_dig_node(pos, oldnode, oldmetadata, digger) end, @@ -401,16 +398,16 @@ minetest.register_node("tubelib_addons1:quarry_defect", { State:defect(pos, M(pos)) end, - on_dig = function(pos, node, puncher, pointed_thing) - if minetest.is_protected(pos, puncher:get_player_name()) then - return - end - local meta = M(pos) - local inv = meta:get_inventory() - if inv:is_empty("main") then - minetest.node_dig(pos, node, puncher, pointed_thing) - tubelib.remove_node(pos) + can_dig = function(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false end + local inv = M(pos):get_inventory() + return inv:is_empty("main") + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) end, on_rotate = screwdriver.disallow, diff --git a/tubelib_addons1/reformer.lua b/tubelib_addons1/reformer.lua index 2d18237..9ebc61d 100644 --- a/tubelib_addons1/reformer.lua +++ b/tubelib_addons1/reformer.lua @@ -171,18 +171,19 @@ minetest.register_node("tubelib_addons1:reformer", { local number = tubelib.add_node(pos, "tubelib_addons1:reformer") State:node_init(pos, number) end, - + + -- the reformer needs 'on_dig' to be able to remove the upper node on_dig = function(pos, node, puncher, pointed_thing) 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}) - tubelib.remove_node(pos) end end, after_dig_node = function(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) State:after_dig_node(pos, oldnode, oldmetadata, digger) end, @@ -203,7 +204,7 @@ minetest.register_node("tubelib_addons1:reformer", { }) minetest.register_node("tubelib_addons1:reformer_defect", { - description = "Tubelib Reformer", + description = "Tubelib Reformer defect", inventory_image = "tubelib_addons1_reformer_inventory.png", tiles = { -- up, down, right, left, back, front @@ -238,16 +239,20 @@ minetest.register_node("tubelib_addons1:reformer_defect", { State:defect(pos, M(pos)) end, + -- the reformer needs 'on_dig' to be able to remove the upper node on_dig = function(pos, node, puncher, pointed_thing) 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}) - tubelib.remove_node(pos) end end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) + end, + on_rotate = screwdriver.disallow, allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_move = allow_metadata_inventory_move, diff --git a/tubelib_addons2/colorlamp.lua b/tubelib_addons2/colorlamp.lua index 39c2ce6..93b8488 100644 --- a/tubelib_addons2/colorlamp.lua +++ b/tubelib_addons2/colorlamp.lua @@ -115,6 +115,10 @@ for idx,color in ipairs(tColors) do switch_node(pos, "", clicker) end, + after_dig_node = function(pos) + tubelib.remove_node(pos) + end, + paramtype = 'light', light_source = minetest.LIGHT_MAX, groups = {choppy=2, cracky=1, not_in_creative_inventory=1}, diff --git a/tubelib_addons2/industriallamp.lua b/tubelib_addons2/industriallamp.lua index 6fb52d5..d6a29c3 100644 --- a/tubelib_addons2/industriallamp.lua +++ b/tubelib_addons2/industriallamp.lua @@ -83,6 +83,10 @@ local function register_lamp(tbl) end end, + after_dig_node = function(pos) + tubelib.remove_node(pos) + end, + paramtype = "light", light_source = minetest.LIGHT_MAX, sunlight_propagates = true, diff --git a/tubelib_addons2/programmer.lua b/tubelib_addons2/programmer.lua index ae9f3ba..fe83da7 100644 --- a/tubelib_addons2/programmer.lua +++ b/tubelib_addons2/programmer.lua @@ -13,7 +13,7 @@ ]]-- local function join_to_string(tbl) - t = {} + local t = {} for key,_ in pairs(tbl) do t[#t + 1] = key .. " " end diff --git a/tubelib_addons3/distributor.lua b/tubelib_addons3/distributor.lua index 4e7911d..eac6dee 100644 --- a/tubelib_addons3/distributor.lua +++ b/tubelib_addons3/distributor.lua @@ -26,7 +26,7 @@ local STANDBY_TICKS = 4 local CYCLE_TIME = 2 local function formspec(self, pos, meta) - local filter = minetest.deserialize(meta:get_string("filter")) + local filter = minetest.deserialize(meta:get_string("filter")) or {false,false,false,false} return "size[10.5,8.5]".. default.gui_bg.. default.gui_bg_img.. @@ -329,20 +329,17 @@ minetest.register_node("tubelib_addons3:distributor", { on_receive_fields = on_receive_fields, - on_dig = function(pos, node, puncher, pointed_thing) - if minetest.is_protected(pos, puncher:get_player_name()) then - return - end - local meta = M(pos) - local inv = meta:get_inventory() - if inv:is_empty("src") then - minetest.node_dig(pos, node, puncher, pointed_thing) - tubelib.remove_node(pos) + can_dig = function(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false end + local inv = M(pos):get_inventory() + return inv:is_empty("src") end, after_dig_node = function(pos, oldnode, oldmetadata, digger) State:after_dig_node(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) end, allow_metadata_inventory_put = allow_metadata_inventory_put, @@ -415,11 +412,11 @@ minetest.register_node("tubelib_addons3:distributor_defect", { after_place_node = function(pos, placer) local meta = M(pos) local number = tubelib.add_node(pos, "tubelib_addons3:distributor") + local filter = {false,false,false,false} + meta:set_string("filter", minetest.serialize(filter)) State:node_init(pos, number) meta:set_string("player_name", placer:get_player_name()) - local filter = {false,false,false,false} - meta:set_string("filter", minetest.serialize(filter)) local inv = meta:get_inventory() inv:set_size('src', 8) inv:set_size('yellow', 6) @@ -432,6 +429,18 @@ minetest.register_node("tubelib_addons3:distributor_defect", { on_receive_fields = on_receive_fields, + can_dig = function(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false + end + local inv = M(pos):get_inventory() + return inv:is_empty("src") + end, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) + end, + allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_take = allow_metadata_inventory_take, allow_metadata_inventory_move = allow_metadata_inventory_move, diff --git a/tubelib_addons3/pushing_chest.lua b/tubelib_addons3/pushing_chest.lua index 161b5c1..01c4b4a 100644 --- a/tubelib_addons3/pushing_chest.lua +++ b/tubelib_addons3/pushing_chest.lua @@ -59,6 +59,17 @@ local function aging(pos, meta) end end +local function after_dig_node(pos, oldnode, oldmetadata, digger) + local inv = minetest.get_inventory({type="player", name=digger:get_player_name()}) + local cnt = oldmetadata.fields.tubelib_aging and tonumber(oldmetadata.fields.tubelib_aging) or 0 + local is_defect = cnt > AGING_LEVEL1 and math.random(AGING_LEVEL2 / cnt) == 1 + if is_defect then + inv:add_item("main", ItemStack("tubelib_addons3:pushing_chest_defect")) + else + inv:add_item("main", ItemStack("tubelib_addons3:pushing_chest")) + end +end + local function set_state(meta, state) local number = meta:get_string("number") meta:set_string("infotext", "HighPerf Pushing Chest "..number..": "..state) @@ -161,17 +172,18 @@ minetest.register_node("tubelib_addons3:pushing_chest", { minetest.get_node_timer(pos):start(2) end, - can_dig = function(pos,player) + can_dig = function(pos, player) if minetest.is_protected(pos, player:get_player_name()) then return false end - local meta = minetest.get_meta(pos); + local meta = minetest.get_meta(pos) local inv = meta:get_inventory() return inv:is_empty("main") and inv:is_empty("shift") end, - - on_dig = function(pos, node, puncher, pointed_thing) - minetest.node_dig(pos, node, puncher, pointed_thing) + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + after_dig_node(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) end, allow_metadata_inventory_put = allow_metadata_inventory_put, @@ -181,6 +193,7 @@ minetest.register_node("tubelib_addons3:pushing_chest", { on_timer = shift_items, on_rotate = screwdriver.disallow, + drop = "", paramtype = "light", sunlight_propagates = true, paramtype2 = "facedir", @@ -217,17 +230,16 @@ minetest.register_node("tubelib_addons3:pushing_chest_defect", { set_state(meta, "empty") end, - can_dig = function(pos,player) + can_dig = function(pos, player) if minetest.is_protected(pos, player:get_player_name()) then return false end - local meta = minetest.get_meta(pos); - local inv = meta:get_inventory() + local inv = minetest.get_meta(pos):get_inventory() return inv:is_empty("main") and inv:is_empty("shift") end, - - on_dig = function(pos, node, puncher, pointed_thing) - minetest.node_dig(pos, node, puncher, pointed_thing) + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + tubelib.remove_node(pos) end, allow_metadata_inventory_put = allow_metadata_inventory_put, @@ -265,6 +277,8 @@ tubelib.register_node("tubelib_addons3:pushing_chest", return "empty" end return meta:get_string("state") + elseif topic == "aging" then + return minetest.get_meta(pos):get_int("tubelib_aging") else return "not supported" end @@ -298,10 +312,6 @@ tubelib.register_node("tubelib_addons3:pushing_chest", local meta = minetest.get_meta(pos) return tubelib.put_item(meta, "main", item) end, - - on_recv_message = function(pos, topic, payload) - return "unsupported" - end, on_node_load = function(pos) minetest.get_node_timer(pos):start(2) end,