From 16fefca1fa3be661ce0d8f8cd3ab00bbe573f73c Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Fri, 22 Jun 2018 20:50:19 +0200 Subject: [PATCH] Further "tubing" improvements: - ignore none inventory nodes (lamps,...) - connect tubes for inventory nodes --- tubelib/command.lua | 9 +++++++-- tubelib/pusher.lua | 1 + tubelib/tubes1.lua | 33 ++++++++++++++++++++------------- tubelib_addons1/pusher_fast.lua | 1 + 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/tubelib/command.lua b/tubelib/command.lua index 4d5c5ae..933281b 100644 --- a/tubelib/command.lua +++ b/tubelib/command.lua @@ -203,12 +203,17 @@ end function tubelib.register_node(name, add_names, node_definition) tubelib_NodeDef[name] = node_definition -- store facedir table for all known node names - tubelib.KnownNodes[name] = true Name2Name[name] = name for _,n in ipairs(add_names) do - tubelib.KnownNodes[n] = true Name2Name[n] = name end + if node_definition.on_pull_item or node_definition.on_push_item or + node_definition.is_pusher then + tubelib.KnownNodes[name] = true + for _,n in ipairs(add_names) do + tubelib.KnownNodes[n] = true + end + end end ------------------------------------------------------------------- diff --git a/tubelib/pusher.lua b/tubelib/pusher.lua index 012efc3..48d58d5 100644 --- a/tubelib/pusher.lua +++ b/tubelib/pusher.lua @@ -226,6 +226,7 @@ tubelib.register_node("tubelib:pusher", {"tubelib:pusher_active"}, { on_pull_item = nil, -- pusher has no inventory on_push_item = nil, -- pusher has no inventory on_unpull_item = nil, -- pusher has no inventory + is_pusher = true, -- is a pulling/pushing node on_recv_message = function(pos, topic, payload) local node = minetest.get_node(pos) diff --git a/tubelib/tubes1.lua b/tubelib/tubes1.lua index aba7954..15cfcba 100644 --- a/tubelib/tubes1.lua +++ b/tubelib/tubes1.lua @@ -141,13 +141,15 @@ function tubelib.get_next_tube(pos, dir) return pos, nil end -local function get_next_node(pos, dir) - pos = get_tube_pos(pos, dir) - local node = minetest.get_node_or_nil(pos) or tubelib.read_node_with_vm(pos) - if tubelib.KnownNodes[node.name] then - return node +local function is_known_node(pos, dir) + if dir then + pos = get_tube_pos(pos, dir) + local node = minetest.get_node_or_nil(pos) or tubelib.read_node_with_vm(pos) + if tubelib.KnownNodes[node.name] and not tubelib.TubeNames[node.name] then + return true + end end - return nil + return false end @@ -204,7 +206,7 @@ local function is_connected(pos, dir) local dir1,dir2 = get_tube_dirs(pos) -- return true if connected dir = Turn180Deg[dir] - return dir == dir1 or dir == dir2 + return dir == dir1 or dir == dir2 end return false end @@ -222,8 +224,8 @@ end local function update_next_tube(dir, pos) -- test if tube is connected with neighbor tubes local dir1, dir2 = get_tube_dirs(pos) - local conn1 = is_connected(pos, dir1) - local conn2 = is_connected(pos, dir2) + local conn1 = is_connected(pos, dir1) or is_known_node(pos, dir1) + local conn2 = is_connected(pos, dir2) or is_known_node(pos, dir2) -- already connected or no tube arround? if conn1 == conn2 then return @@ -246,12 +248,17 @@ local function update_tube(pos, dir) for dir = 1,6 do if not dir1 and is_connected(pos, dir) then dir1 = dir - elseif not dir1 and get_next_node(pos, dir) then - dir1 = dir elseif not dir2 and is_connected(pos, dir) then dir2 = dir - elseif not dir2 and get_next_node(pos, dir) then - dir2 = dir + end + end + if not dir1 or not dir2 then + for dir = 1,6 do + if not dir1 and is_known_node(pos, dir) then + dir1 = dir + elseif not dir2 and is_known_node(pos, dir) then + dir2 = dir + end end end dir1 = dir1 or dir diff --git a/tubelib_addons1/pusher_fast.lua b/tubelib_addons1/pusher_fast.lua index 9ae58a2..ee8ba89 100644 --- a/tubelib_addons1/pusher_fast.lua +++ b/tubelib_addons1/pusher_fast.lua @@ -226,6 +226,7 @@ tubelib.register_node("tubelib_addons1:pusher_fast", {"tubelib_addons1:pusher_fa on_pull_item = nil, -- pusher has no inventory on_push_item = nil, -- pusher has no inventory on_unpull_item = nil, -- pusher has no inventory + is_pusher = true, -- is a pulling/pushing node on_recv_message = function(pos, topic, payload) local node = minetest.get_node(pos)