From f2aa5c1c9566f6ff2796b8e9d20fe6f737a3147e Mon Sep 17 00:00:00 2001 From: HybridDog Date: Wed, 18 Nov 2015 10:36:23 +0100 Subject: [PATCH] fix pipeworks item inserting support, closes #1 --- README.txt | 1 - init.lua | 46 +++++++++++++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/README.txt b/README.txt index 02c9294..53b95e2 100644 --- a/README.txt +++ b/README.txt @@ -1,3 +1,2 @@ TODO: — disallow rotating the chest with a screwdriver -— test inserting items in the right side diff --git a/init.lua b/init.lua index 9c4f026..a9a5f2e 100644 --- a/init.lua +++ b/init.lua @@ -225,20 +225,29 @@ end minetest.register_node("connected_chests:chest_locked_left", chest_locked) -local tube_to_left_locked = { - insert_object = function(pos, node, stack) - local x, z = unpack(string.split(param_tab2[node.param2], " ")) - return minetest.get_meta({x=pos.x+x, y=pos.y, z=pos.z+z}):get_inventory():add_item("main", stack) - end, - can_insert = function(pos, node, stack) - local x, z = unpack(string.split(param_tab2[node.param2], " ")) - return minetest.get_meta({x=pos.x+x, y=pos.y, z=pos.z+z}):get_inventory():room_for_item("main", stack) - end, - connect_sides = {right = 1, back = 1, front = 1, bottom = 1, top = 1} -} +local tube_to_left, tube_to_left_locked, tube_update, tube_groups +if minetest.global_exists("pipeworks") then + tube_to_left_locked = { + insert_object = function(pos, node, stack) + local x, z = unpack(string.split(param_tab2[node.param2], " ")) + return minetest.get_meta({x=pos.x+x, y=pos.y, z=pos.z+z}):get_inventory():add_item("main", stack) + end, + can_insert = function(pos, node, stack) + local x, z = unpack(string.split(param_tab2[node.param2], " ")) + return minetest.get_meta({x=pos.x+x, y=pos.y, z=pos.z+z}):get_inventory():room_for_item("main", stack) + end, + connect_sides = {right = 1, back = 1, front = 1, bottom = 1, top = 1} + } -local tube_to_left = table.copy(tube_to_left_locked) -tube_to_left.input_inventory = "main" + tube_to_left = table.copy(tube_to_left_locked) + tube_to_left.input_inventory = "main" + + tube_update = pipeworks.scan_for_tube_objects + + tube_groups = {tubedevice=1, tubedevice_receiver=1} +else + function tube_update() end +end minetest.register_node("connected_chests:chest_right", { tiles = {top_texture.."^[transformFX", top_texture.."^[transformFX", "default_chest_side.png", @@ -259,7 +268,9 @@ minetest.register_node("connected_chests:chest_right", { if node_left.name ~= "connected_chests:chest_left" or node_left.param2 ~= node.param2 then minetest.remove_node(pos) + return end + tube_update(pos) end, after_destruct = function(pos, oldnode) if oldnode.param2 > 3 then @@ -271,9 +282,12 @@ minetest.register_node("connected_chests:chest_right", { and node_left.param2 == oldnode.param2 and minetest.get_node(pos).name == "air" then minetest.set_node(pos, oldnode) + return end + tube_update(pos) end, tube = tube_to_left, + groups = tube_groups, }) minetest.register_node("connected_chests:chest_locked_right", { @@ -287,6 +301,7 @@ minetest.register_node("connected_chests:chest_locked_right", { local node = minetest.get_node(pos) if node.param2 > 3 then node.param2 = node.param2%4 + -- ↓ calls the on_construct from the beginning again minetest.set_node(pos, node) return end @@ -295,7 +310,9 @@ minetest.register_node("connected_chests:chest_locked_right", { if node_left.name ~= "connected_chests:chest_locked_left" or node_left.param2 ~= node.param2 then minetest.remove_node(pos) + return end + tube_update(pos) end, after_destruct = function(pos, oldnode) if oldnode.param2 > 3 then @@ -307,9 +324,12 @@ minetest.register_node("connected_chests:chest_locked_right", { and node_left.param2 == oldnode.param2 and minetest.get_node(pos).name == "air" then minetest.set_node(pos, oldnode) + return end + tube_update(pos) end, tube = tube_to_left_locked, + groups = tube_groups, }) -- abms to fix half chests