diff --git a/tubelib/tubes1.lua b/tubelib/tubes1.lua index ee16b23..dc7b6f6 100644 --- a/tubelib/tubes1.lua +++ b/tubelib/tubes1.lua @@ -231,8 +231,10 @@ local function update_next_tube(dir, pos) if (conn1 and conn2) or (not dir1 and not dir2) then return elseif not conn1 and not conn2 then - dir1 = Turn90Deg[dir1] - dir2 = Turn180Deg[dir1] + if dir1 ~= dir and dir2 ~= dir then + dir1 = Turn90Deg[dir1] + dir2 = Turn180Deg[dir1] + end elseif conn1 then dir2 = Turn180Deg[dir] else @@ -243,34 +245,40 @@ local function update_next_tube(dir, pos) end -- update new placed tube -local function update_tube(pos, dir) +local function update_tube(pos, dir, force_dir) local dir1 = nil local dir2 = nil - -- search on all 6 pos for up to 2 tubes with open holes or - -- other tubelib compatible nodes - for dir = 1,6 do - if not dir1 and is_connected(pos, dir) then - dir1 = dir - elseif not dir2 and is_connected(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 + -- use the predefined direction? + if force_dir then + dir1 = Turn180Deg[dir] + dir2 = force_dir + else + -- search on all 6 pos for up to 2 tubes with open holes or + -- other tubelib compatible nodes + for ndir = 1,6 do + if not dir1 and is_connected(pos, ndir) then + dir1 = ndir + elseif not dir2 and is_connected(pos, ndir) then + dir2 = ndir end end + if not dir1 or not dir2 then + for ndir = 1,6 do + if not dir1 and is_known_node(pos, ndir) then + dir1 = ndir + elseif not dir2 and is_known_node(pos, ndir) then + dir2 = ndir + end + end + end + dir1 = dir1 or dir + dir2 = dir2 or Turn180Deg[dir] end - dir1 = dir1 or dir - dir2 = dir2 or Turn180Deg[dir] local node_num, param2 = get_tube_number_and_param2(dir1, dir2) swap_node(pos, node_num, param2) end -function tubelib.update_tubes(pos, dir, straight_ahead) +function tubelib.update_tubes(pos, dir, force_dir, straight_ahead) -- Update all tubes arround the currently placed tube update_next_tube(1, {x=pos.x , y=pos.y , z=pos.z+1}) update_next_tube(2, {x=pos.x+1, y=pos.y , z=pos.z }) @@ -280,7 +288,7 @@ function tubelib.update_tubes(pos, dir, straight_ahead) update_next_tube(6, {x=pos.x , y=pos.y+1, z=pos.z }) if not straight_ahead then -- Update the placed tube - update_tube(pos, dir) + update_tube(pos, dir, force_dir) end return tubelib.delete_meta_data(pos, minetest.get_node(pos)) < MAX_TUBE_LENGTH end diff --git a/tubelib/tubes2.lua b/tubelib/tubes2.lua index 20e77ca..445e269 100644 --- a/tubelib/tubes2.lua +++ b/tubelib/tubes2.lua @@ -51,6 +51,16 @@ local function remote_node(pos, dir) return pos1, dir end +local function is_known_node(pointed_thing) + if pointed_thing.type == "node" then + local node = minetest.get_node(pointed_thing.under) + if tubelib.KnownNodes[node.name] and not tubelib.TubeNames[node.name] then + return pointed_thing.under + end + end + return nil +end + -- Determine neighbor position and own facedir to the node. -- based on own pos and contact side 'B' - 'U'. -- Function considers also tube connections. @@ -172,19 +182,22 @@ for idx,pos in ipairs(DirCorrections) do }, after_place_node = function(pos, placer, itemstack, pointed_thing) - local res + local dir1 = nil + local dir2 = nil local pitch = placer:get_look_pitch() - local straight_ahead = placer:get_player_control().sneak - if pitch > 1 then - res = tubelib.update_tubes(pos, 6, straight_ahead) - elseif pitch < -1 then - res = tubelib.update_tubes(pos, 5, straight_ahead) - else - local dir = placer:get_look_dir() - local facedir = minetest.dir_to_facedir(dir) - res = tubelib.update_tubes(pos, facedir + 1, straight_ahead) + local known_pos = is_known_node(pointed_thing) + local straight_ahead = placer:get_player_control().sneak and not known_pos + if known_pos then -- placer pointed to a known node (chest) + dir2 = dir_to_facedir(pos, known_pos) + 1 end - if res == false then + if pitch > 1 then -- up? + dir1 = 6 + elseif pitch < -1 then -- down? + dir1 = 5 + else + dir1 = minetest.dir_to_facedir(placer:get_look_dir()) + 1 + end + if not tubelib.update_tubes(pos, dir1, dir2, straight_ahead) then tubelib.delete_meta_data(pos, minetest.get_node(pos)) minetest.remove_node(pos) return itemstack