mirror of
https://github.com/joe7575/tubelib2.git
synced 2024-08-19 21:14:22 +02:00
v1.8 * 'special nodes' as alternative to 'secondary nodes' introduced
This commit is contained in:
parent
db90c07dfd
commit
e307045268
@ -79,5 +79,6 @@ Textures: CC0
|
|||||||
- 2019-07-12 v1.5 * internal handling of secondary nodes changed
|
- 2019-07-12 v1.5 * internal handling of secondary nodes changed
|
||||||
- 2019-10-25 v1.6 * callback 'tubelib2_on_update2' added
|
- 2019-10-25 v1.6 * callback 'tubelib2_on_update2' added
|
||||||
- 2020-01-03 v1.7 * max_tube_length bugfix
|
- 2020-01-03 v1.7 * max_tube_length bugfix
|
||||||
|
- 2020-02-02 v1.8 * 'special nodes' as alternative to 'secondary nodes' introduced
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,8 +101,7 @@ function Tube:update_secondary_node(pos1, dir1, pos2, dir2)
|
|||||||
ndef.tubelib2_on_update2(pos1, dir1, self, node)
|
ndef.tubelib2_on_update2(pos1, dir1, self, node)
|
||||||
elseif ndef.tubelib2_on_update then
|
elseif ndef.tubelib2_on_update then
|
||||||
ndef.tubelib2_on_update(node, pos1, dir1, pos2, Turn180Deg[dir2])
|
ndef.tubelib2_on_update(node, pos1, dir1, pos2, Turn180Deg[dir2])
|
||||||
end
|
elseif self.clbk_update_secondary_node then
|
||||||
if self.clbk_update_secondary_node then
|
|
||||||
self.clbk_update_secondary_node(node, pos1, dir1, pos2, Turn180Deg[dir2])
|
self.clbk_update_secondary_node(node, pos1, dir1, pos2, Turn180Deg[dir2])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -123,6 +123,17 @@ function Tube:get_secondary_node(pos, dir)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Get special registered nodes at given position
|
||||||
|
-- If dir == nil then node_pos = pos
|
||||||
|
-- Function returns node and new_pos or nil
|
||||||
|
function Tube:get_special_node(pos, dir)
|
||||||
|
local npos = vector.add(pos, Dir6dToVector[dir or 0])
|
||||||
|
local node = self:get_node_lvm(npos)
|
||||||
|
if self.special_node_names[node.name] then
|
||||||
|
return node, npos
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Check if node at given position is a secondary node
|
-- Check if node at given position is a secondary node
|
||||||
-- If dir == nil then node_pos = pos
|
-- If dir == nil then node_pos = pos
|
||||||
-- Function returns true/false
|
-- Function returns true/false
|
||||||
@ -132,6 +143,15 @@ function Tube:is_secondary_node(pos, dir)
|
|||||||
return self.secondary_node_names[node.name]
|
return self.secondary_node_names[node.name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Check if node at given position is a special node
|
||||||
|
-- If dir == nil then node_pos = pos
|
||||||
|
-- Function returns true/false
|
||||||
|
function Tube:is_special_node(pos, dir)
|
||||||
|
local npos = vector.add(pos, Dir6dToVector[dir or 0])
|
||||||
|
local node = self:get_node_lvm(npos)
|
||||||
|
return self.special_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:is_secondary_node(pos, dir)
|
return self:is_primary_node(pos, dir) or self:is_secondary_node(pos, dir)
|
||||||
|
40
tube_api.lua
40
tube_api.lua
@ -13,7 +13,7 @@
|
|||||||
]]--
|
]]--
|
||||||
|
|
||||||
-- Version for compatibility checks, see readme.md/history
|
-- Version for compatibility checks, see readme.md/history
|
||||||
tubelib2.version = 1.7
|
tubelib2.version = 1.8
|
||||||
|
|
||||||
-- for lazy programmers
|
-- for lazy programmers
|
||||||
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||||
@ -113,10 +113,17 @@ local function update3(self, pos, dir1, dir2)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update4(self, pos, dirs)
|
local function update_secondary_nodes_after_node_placed(self, pos, dirs)
|
||||||
dirs = dirs or self.dirs_to_check
|
dirs = dirs or self.dirs_to_check
|
||||||
|
-- check surrounding for secondary nodes
|
||||||
for _,dir in ipairs(dirs) do
|
for _,dir in ipairs(dirs) do
|
||||||
local _,npos = self:get_secondary_node(pos, dir)
|
local tmp, npos
|
||||||
|
if self.force_to_use_tubes then
|
||||||
|
tmp, npos = self:get_special_node(pos, dir)
|
||||||
|
print("tmp, npos", tmp, S(npos))
|
||||||
|
else
|
||||||
|
tmp, npos = self:get_secondary_node(pos, dir)
|
||||||
|
end
|
||||||
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])
|
||||||
@ -124,10 +131,16 @@ local function update4(self, pos, dirs)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update5(self, pos, dirs)
|
local function update_secondary_nodes_after_node_dug(self, pos, dirs)
|
||||||
dirs = dirs or self.dirs_to_check
|
dirs = dirs or self.dirs_to_check
|
||||||
|
-- check surrounding for secondary nodes
|
||||||
for _,dir in ipairs(dirs) do
|
for _,dir in ipairs(dirs) do
|
||||||
local _,npos = self:get_secondary_node(pos, dir)
|
local tmp, npos
|
||||||
|
if self.force_to_use_tubes then
|
||||||
|
tmp, npos = self:get_special_node(pos, dir)
|
||||||
|
else
|
||||||
|
tmp, npos = self:get_secondary_node(pos, dir)
|
||||||
|
end
|
||||||
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)
|
||||||
@ -151,6 +164,7 @@ function Tube:new(attr)
|
|||||||
tube_type = attr.tube_type or "unknown",
|
tube_type = attr.tube_type or "unknown",
|
||||||
pairingList = {}, -- teleporting nodes
|
pairingList = {}, -- teleporting nodes
|
||||||
connCache = {}, -- connection cache {pos1 = {dir1 = {pos2 = pos2, dir2 = dir2},...}
|
connCache = {}, -- connection cache {pos1 = {dir1 = {pos2 = pos2, dir2 = dir2},...}
|
||||||
|
special_node_names = {}, -- use add_special_node_names() to register nodes
|
||||||
}
|
}
|
||||||
o.valid_dirs = Tbl(o.dirs_to_check)
|
o.valid_dirs = Tbl(o.dirs_to_check)
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
@ -165,6 +179,14 @@ function Tube:add_secondary_node_names(names)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Register further nodes, which should be updated after
|
||||||
|
-- a node/tube is placed/dug
|
||||||
|
function Tube:add_special_node_names(names)
|
||||||
|
for _,name in ipairs(names) do
|
||||||
|
self.special_node_names[name] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Called for each connected node when the tube connection has been changed.
|
-- Called for each connected node when the tube connection has been changed.
|
||||||
-- func(node, pos, out_dir, peer_pos, peer_in_dir)
|
-- func(node, pos, out_dir, peer_pos, peer_in_dir)
|
||||||
function Tube:register_on_tube_update(update_secondary_node)
|
function Tube:register_on_tube_update(update_secondary_node)
|
||||||
@ -185,9 +207,7 @@ function Tube:after_place_node(pos, dirs)
|
|||||||
update1(self, pos, dir)
|
update1(self, pos, dir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not self.force_to_use_tubes then
|
update_secondary_nodes_after_node_placed(self, pos, dirs)
|
||||||
update4(self, pos, dirs)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- To be called after a tube/primary node is placed.
|
-- To be called after a tube/primary node is placed.
|
||||||
@ -208,9 +228,7 @@ function Tube:after_dig_node(pos, dirs)
|
|||||||
for _,dir in ipairs(self:update_after_dig_node(pos, dirs)) do
|
for _,dir in ipairs(self:update_after_dig_node(pos, dirs)) do
|
||||||
update1(self, pos, dir)
|
update1(self, pos, dir)
|
||||||
end
|
end
|
||||||
if not self.force_to_use_tubes then
|
update_secondary_nodes_after_node_dug(self, pos, dirs)
|
||||||
update5(self, pos, dirs)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- To be called after a tube/primary node is removed.
|
-- To be called after a tube/primary node is removed.
|
||||||
|
Loading…
Reference in New Issue
Block a user