Further "tubing" improvements:

- ignore none inventory nodes (lamps,...)
- connect tubes for inventory nodes
This commit is contained in:
Joachim Stolberg 2018-06-22 20:50:19 +02:00
parent b291a3171b
commit 16fefca1fa
4 changed files with 29 additions and 15 deletions

@ -203,12 +203,17 @@ end
function tubelib.register_node(name, add_names, node_definition) function tubelib.register_node(name, add_names, node_definition)
tubelib_NodeDef[name] = node_definition tubelib_NodeDef[name] = node_definition
-- store facedir table for all known node names -- store facedir table for all known node names
tubelib.KnownNodes[name] = true
Name2Name[name] = name Name2Name[name] = name
for _,n in ipairs(add_names) do for _,n in ipairs(add_names) do
tubelib.KnownNodes[n] = true
Name2Name[n] = name Name2Name[n] = name
end 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 end
------------------------------------------------------------------- -------------------------------------------------------------------

@ -226,6 +226,7 @@ tubelib.register_node("tubelib:pusher", {"tubelib:pusher_active"}, {
on_pull_item = nil, -- pusher has no inventory on_pull_item = nil, -- pusher has no inventory
on_push_item = nil, -- pusher has no inventory on_push_item = nil, -- pusher has no inventory
on_unpull_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) on_recv_message = function(pos, topic, payload)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)

@ -141,13 +141,15 @@ function tubelib.get_next_tube(pos, dir)
return pos, nil return pos, nil
end end
local function get_next_node(pos, dir) local function is_known_node(pos, dir)
pos = get_tube_pos(pos, dir) if dir then
local node = minetest.get_node_or_nil(pos) or tubelib.read_node_with_vm(pos) pos = get_tube_pos(pos, dir)
if tubelib.KnownNodes[node.name] then local node = minetest.get_node_or_nil(pos) or tubelib.read_node_with_vm(pos)
return node if tubelib.KnownNodes[node.name] and not tubelib.TubeNames[node.name] then
return true
end
end end
return nil return false
end end
@ -204,7 +206,7 @@ local function is_connected(pos, dir)
local dir1,dir2 = get_tube_dirs(pos) local dir1,dir2 = get_tube_dirs(pos)
-- return true if connected -- return true if connected
dir = Turn180Deg[dir] dir = Turn180Deg[dir]
return dir == dir1 or dir == dir2 return dir == dir1 or dir == dir2
end end
return false return false
end end
@ -222,8 +224,8 @@ end
local function update_next_tube(dir, pos) local function update_next_tube(dir, pos)
-- test if tube is connected with neighbor tubes -- test if tube is connected with neighbor tubes
local dir1, dir2 = get_tube_dirs(pos) local dir1, dir2 = get_tube_dirs(pos)
local conn1 = is_connected(pos, dir1) local conn1 = is_connected(pos, dir1) or is_known_node(pos, dir1)
local conn2 = is_connected(pos, dir2) local conn2 = is_connected(pos, dir2) or is_known_node(pos, dir2)
-- already connected or no tube arround? -- already connected or no tube arround?
if conn1 == conn2 then if conn1 == conn2 then
return return
@ -246,12 +248,17 @@ local function update_tube(pos, dir)
for dir = 1,6 do for dir = 1,6 do
if not dir1 and is_connected(pos, dir) then if not dir1 and is_connected(pos, dir) then
dir1 = dir dir1 = dir
elseif not dir1 and get_next_node(pos, dir) then
dir1 = dir
elseif not dir2 and is_connected(pos, dir) then elseif not dir2 and is_connected(pos, dir) then
dir2 = dir dir2 = dir
elseif not dir2 and get_next_node(pos, dir) then end
dir2 = dir 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
end end
dir1 = dir1 or dir dir1 = dir1 or dir

@ -226,6 +226,7 @@ tubelib.register_node("tubelib_addons1:pusher_fast", {"tubelib_addons1:pusher_fa
on_pull_item = nil, -- pusher has no inventory on_pull_item = nil, -- pusher has no inventory
on_push_item = nil, -- pusher has no inventory on_push_item = nil, -- pusher has no inventory
on_unpull_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) on_recv_message = function(pos, topic, payload)
local node = minetest.get_node(pos) local node = minetest.get_node(pos)