internal handling of secondary nodes changed

This commit is contained in:
Joachim Stolberg 2019-07-12 23:25:20 +02:00
parent ba57e8679f
commit e3e30e7b27
5 changed files with 21 additions and 11 deletions

@ -76,3 +76,4 @@ Textures: CC0
- 2019-04-18 v1.2 * 'force_to_use_tubes' added
- 2019-05-01 v1.3 * API function 'compatible_node' added
- 2019-05-09 v1.4 * Attribute 'tube_type' added
- 2019-07-12 v1.5 * internal handling of secondary nodes changed

@ -94,8 +94,8 @@ end
-- pos/dir are the pos of the secondary nodes pointing to the head tube nodes.
function Tube:update_secondary_node(pos1, dir1, pos2, dir2)
local _, node = self:get_node(pos1)
if self.secondary_node_names[node.name] then
local node,_ = self:get_secondary_node(pos1)
if node then
if (minetest.registered_nodes[node.name] or {}).tubelib2_on_update then
minetest.registered_nodes[node.name].tubelib2_on_update(node, pos1, dir1, pos2, Turn180Deg[dir2])
elseif self.clbk_update_secondary_node then

@ -112,20 +112,29 @@ function Tube:is_primary_node(pos, dir)
return self.primary_node_names[node.name]
end
-- Check if node at given position is a secondary node
-- Get secondary node at given position
-- If dir == nil then node_pos = pos
-- Function returns the new pos or nil
function Tube:secondary_node(pos, dir)
-- Function returns node and new_pos or nil
function Tube:get_secondary_node(pos, dir)
local npos = vector.add(pos, Dir6dToVector[dir or 0])
local node = self:get_node_lvm(npos)
if self.secondary_node_names[node.name] then
return npos
return node, npos
end
end
-- Check if node at given position is a secondary node
-- If dir == nil then node_pos = pos
-- Function returns true/false
function Tube:is_secondary_node(pos, dir)
local npos = vector.add(pos, Dir6dToVector[dir or 0])
local node = self:get_node_lvm(npos)
return self.secondary_node_names[node.name]
end
-- Check if node has a connection on the given dir
function Tube:connected(pos, dir)
return self:is_primary_node(pos, dir) or self:secondary_node(pos, dir)
return self:is_primary_node(pos, dir) or self:is_secondary_node(pos, dir)
end
function Tube:get_next_tube(pos, dir)
@ -252,7 +261,7 @@ function Tube:determine_tube_dirs(pos, preferred_pos, fdir)
-- Check for secondary nodes (chests and so on)
for dir = 1,6 do
if allowed[dir] then
local npos = self:secondary_node(pos, dir)
local _,npos = self:get_secondary_node(pos, dir)
if npos then
if preferred_pos and vector.equals(npos, preferred_pos) then
preferred_pos = nil

@ -116,7 +116,7 @@ end
local function update4(self, pos, dirs)
dirs = dirs or self.dirs_to_check
for _,dir in ipairs(dirs) do
local npos = self:secondary_node(pos, dir)
local _,npos = self:get_secondary_node(pos, dir)
if npos then
self:update_secondary_node(npos, Turn180Deg[dir], pos, dir)
self:update_secondary_node(pos, dir, npos, Turn180Deg[dir])
@ -127,7 +127,7 @@ end
local function update5(self, pos, dirs)
dirs = dirs or self.dirs_to_check
for _,dir in ipairs(dirs) do
local npos = self:secondary_node(pos, dir)
local _,npos = self:get_secondary_node(pos, dir)
if npos then
self:update_secondary_node(npos, Turn180Deg[dir])
self:update_secondary_node(pos, dir)

@ -40,7 +40,7 @@ Tube:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir)
local sdir = tubelib2.dir_to_string(out_dir)
if not peer_pos then
print(S(pos).." to the "..sdir..": Not connected")
elseif Tube:secondary_node(peer_pos) then
elseif Tube:is_secondary_node(peer_pos) then
local node = minetest.get_node(peer_pos)
print(S(pos).." to the "..sdir..": Connected with "..node.name.." at "..S(peer_pos).."/"..peer_in_dir)
else