mirror of
https://github.com/joe7575/tubelib2.git
synced 2024-08-19 13:04:14 +02:00
internal handling of secondary nodes changed
This commit is contained in:
parent
ba57e8679f
commit
e3e30e7b27
@ -76,3 +76,4 @@ Textures: CC0
|
|||||||
- 2019-04-18 v1.2 * 'force_to_use_tubes' added
|
- 2019-04-18 v1.2 * 'force_to_use_tubes' added
|
||||||
- 2019-05-01 v1.3 * API function 'compatible_node' added
|
- 2019-05-01 v1.3 * API function 'compatible_node' added
|
||||||
- 2019-05-09 v1.4 * Attribute 'tube_type' 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.
|
-- pos/dir are the pos of the secondary nodes pointing to the head tube nodes.
|
||||||
function Tube:update_secondary_node(pos1, dir1, pos2, dir2)
|
function Tube:update_secondary_node(pos1, dir1, pos2, dir2)
|
||||||
local _, node = self:get_node(pos1)
|
local node,_ = self:get_secondary_node(pos1)
|
||||||
if self.secondary_node_names[node.name] then
|
if node then
|
||||||
if (minetest.registered_nodes[node.name] or {}).tubelib2_on_update 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])
|
minetest.registered_nodes[node.name].tubelib2_on_update(node, pos1, dir1, pos2, Turn180Deg[dir2])
|
||||||
elseif self.clbk_update_secondary_node then
|
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]
|
return self.primary_node_names[node.name]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if node at given position is a secondary node
|
-- Get secondary node at given position
|
||||||
-- If dir == nil then node_pos = pos
|
-- If dir == nil then node_pos = pos
|
||||||
-- Function returns the new pos or nil
|
-- Function returns node and new_pos or nil
|
||||||
function Tube:secondary_node(pos, dir)
|
function Tube:get_secondary_node(pos, dir)
|
||||||
local npos = vector.add(pos, Dir6dToVector[dir or 0])
|
local npos = vector.add(pos, Dir6dToVector[dir or 0])
|
||||||
local node = self:get_node_lvm(npos)
|
local node = self:get_node_lvm(npos)
|
||||||
if self.secondary_node_names[node.name] then
|
if self.secondary_node_names[node.name] then
|
||||||
return npos
|
return node, npos
|
||||||
end
|
end
|
||||||
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
|
-- Check if node has a connection on the given dir
|
||||||
function Tube:connected(pos, 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
|
end
|
||||||
|
|
||||||
function Tube:get_next_tube(pos, dir)
|
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)
|
-- Check for secondary nodes (chests and so on)
|
||||||
for dir = 1,6 do
|
for dir = 1,6 do
|
||||||
if allowed[dir] then
|
if allowed[dir] then
|
||||||
local npos = self:secondary_node(pos, dir)
|
local _,npos = self:get_secondary_node(pos, dir)
|
||||||
if npos then
|
if npos then
|
||||||
if preferred_pos and vector.equals(npos, preferred_pos) then
|
if preferred_pos and vector.equals(npos, preferred_pos) then
|
||||||
preferred_pos = nil
|
preferred_pos = nil
|
||||||
|
@ -116,7 +116,7 @@ end
|
|||||||
local function update4(self, pos, dirs)
|
local function update4(self, pos, dirs)
|
||||||
dirs = dirs or self.dirs_to_check
|
dirs = dirs or self.dirs_to_check
|
||||||
for _,dir in ipairs(dirs) do
|
for _,dir in ipairs(dirs) do
|
||||||
local npos = self:secondary_node(pos, dir)
|
local _,npos = self:get_secondary_node(pos, dir)
|
||||||
if npos then
|
if npos then
|
||||||
self:update_secondary_node(npos, Turn180Deg[dir], pos, dir)
|
self:update_secondary_node(npos, Turn180Deg[dir], pos, dir)
|
||||||
self:update_secondary_node(pos, dir, npos, Turn180Deg[dir])
|
self:update_secondary_node(pos, dir, npos, Turn180Deg[dir])
|
||||||
@ -127,7 +127,7 @@ end
|
|||||||
local function update5(self, pos, dirs)
|
local function update5(self, pos, dirs)
|
||||||
dirs = dirs or self.dirs_to_check
|
dirs = dirs or self.dirs_to_check
|
||||||
for _,dir in ipairs(dirs) do
|
for _,dir in ipairs(dirs) do
|
||||||
local npos = self:secondary_node(pos, dir)
|
local _,npos = self:get_secondary_node(pos, dir)
|
||||||
if npos then
|
if npos then
|
||||||
self:update_secondary_node(npos, Turn180Deg[dir])
|
self:update_secondary_node(npos, Turn180Deg[dir])
|
||||||
self:update_secondary_node(pos, 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)
|
local sdir = tubelib2.dir_to_string(out_dir)
|
||||||
if not peer_pos then
|
if not peer_pos then
|
||||||
print(S(pos).." to the "..sdir..": Not connected")
|
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)
|
local node = minetest.get_node(peer_pos)
|
||||||
print(S(pos).." to the "..sdir..": Connected with "..node.name.." at "..S(peer_pos).."/"..peer_in_dir)
|
print(S(pos).." to the "..sdir..": Connected with "..node.name.." at "..S(peer_pos).."/"..peer_in_dir)
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user