mirror of
https://github.com/joe7575/tubelib2.git
synced 2024-08-19 21:14:22 +02:00
bugfix
This commit is contained in:
parent
bbff8f8b53
commit
78ea6da8c0
@ -173,17 +173,17 @@ function Tube:repair_tube_line(pos, dir)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- fpos,fdir points to the secondary node to be updated.
|
-- fpos,fdir points to the secondary node to be updated.
|
||||||
-- npos,ndir are used to calculate the connection data to be written.
|
-- npos,ndir are used to calculate the connection data to be stored.
|
||||||
function Tube:update_secondary_node(fpos,fdir, npos,ndir)
|
function Tube:update_secondary_node(fpos,fdir, npos,ndir)
|
||||||
-- [s]<-[n]----[f]->[s]
|
-- [s]<-[n]----[f]->[s]
|
||||||
|
print("update_secondary_node", S(fpos), fdir)
|
||||||
local fpos2, node = self:get_node(fpos, fdir)
|
local fpos2, node = self:get_node(fpos, fdir)
|
||||||
if self.secondary_node_names[node.name] and
|
if self.secondary_node_names[node.name] and self.clbk_update_secondary_node then
|
||||||
minetest.registered_nodes[node.name].tubelib2_on_update then
|
|
||||||
local npos2 = self:get_pos(npos, ndir)
|
local npos2 = self:get_pos(npos, ndir)
|
||||||
if vector.equals(npos2, fpos2) then -- last tube removed?
|
if vector.equals(npos2, fpos2) then -- last tube removed?
|
||||||
npos2,ndir = nil,nil -- used to delete the data base
|
npos2,ndir = nil,nil -- used to delete the data base
|
||||||
end
|
end
|
||||||
minetest.registered_nodes[node.name].tubelib2_on_update(fpos2, Turn180Deg[fdir], npos2, ndir)
|
self.clbk_update_secondary_node(node, fpos2, Turn180Deg[fdir], npos2, ndir)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
13
tube_api.lua
13
tube_api.lua
@ -36,6 +36,8 @@ end
|
|||||||
-- Tubelib2 Class
|
-- Tubelib2 Class
|
||||||
tubelib2.Tube = {}
|
tubelib2.Tube = {}
|
||||||
local Tube = tubelib2.Tube
|
local Tube = tubelib2.Tube
|
||||||
|
local Turn180Deg = tubelib2.Turn180Deg
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- API Functions
|
-- API Functions
|
||||||
@ -64,6 +66,12 @@ function Tube:add_secondary_node_names(names)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Called for each connected node when the tube connection has been changed.
|
||||||
|
-- func(node, pos, out_dir, peer_pos, peer_in_dir)
|
||||||
|
function Tube:register_on_tube_update(update_secondary_node)
|
||||||
|
self.clbk_update_secondary_node = update_secondary_node
|
||||||
|
end
|
||||||
|
|
||||||
-- To be called after a secondary node is placed.
|
-- To be called after a secondary node is placed.
|
||||||
-- dirs is a list with valid dirs, like: {1,2,3,4}
|
-- dirs is a list with valid dirs, like: {1,2,3,4}
|
||||||
function Tube:after_place_node(pos, dirs)
|
function Tube:after_place_node(pos, dirs)
|
||||||
@ -106,6 +114,7 @@ function Tube:after_dig_node(pos, dirs)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- To be called after a tube/primary node is removed.
|
||||||
function Tube:after_dig_tube(pos, oldnode, oldmetadata)
|
function Tube:after_dig_tube(pos, oldnode, oldmetadata)
|
||||||
-- [s1][f1]----[n1] x [n2]-----[f2][s2]
|
-- [s1][f1]----[n1] x [n2]-----[f2][s2]
|
||||||
-- s..secondary, f..far, n..near, x..node to be removed
|
-- s..secondary, f..far, n..near, x..node to be removed
|
||||||
@ -130,9 +139,9 @@ function Tube:get_connected_node_pos(pos, dir)
|
|||||||
-- only one tube with wrong dir info?
|
-- only one tube with wrong dir info?
|
||||||
if vector.equals(pos, npos) then
|
if vector.equals(pos, npos) then
|
||||||
fpos,fdir = self:del_meta(pos, dir)
|
fpos,fdir = self:del_meta(pos, dir)
|
||||||
return self:get_pos(fpos,fdir)
|
npos,ndir = self:get_pos(fpos,fdir)
|
||||||
end
|
end
|
||||||
return npos, dir
|
return npos, fdir
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ local Tube = tubelib2.Tube:new({
|
|||||||
-- dirs_to_check = {5,6}, -- vertical only
|
-- dirs_to_check = {5,6}, -- vertical only
|
||||||
dirs_to_check = {1,2,3,4,5,6},
|
dirs_to_check = {1,2,3,4,5,6},
|
||||||
max_tube_length = 1000,
|
max_tube_length = 1000,
|
||||||
show_infotext = false,
|
show_infotext = true,
|
||||||
primary_node_names = {"tubelib2:tubeS", "tubelib2:tubeA"},
|
primary_node_names = {"tubelib2:tubeS", "tubelib2:tubeA"},
|
||||||
secondary_node_names = {"default:chest", "default:chest_open",
|
secondary_node_names = {"default:chest", "default:chest_open",
|
||||||
"tubelib2:source", "tubelib2:junction", "tubelib2:teleporter"},
|
"tubelib2:source", "tubelib2:junction", "tubelib2:teleporter"},
|
||||||
@ -36,6 +36,19 @@ local Tube = tubelib2.Tube:new({
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
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
|
||||||
|
local node = minetest.get_node(peer_pos)
|
||||||
|
print(S(pos).." to the "..sdir..": Connected with "..node.name)
|
||||||
|
else
|
||||||
|
print(S(pos).." to the "..sdir..": Connected with "..S(peer_pos))
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
minetest.register_node("tubelib2:tubeS", {
|
minetest.register_node("tubelib2:tubeS", {
|
||||||
description = "Tubelib2 Test tube",
|
description = "Tubelib2 Test tube",
|
||||||
tiles = { -- Top, base, right, left, front, back
|
tiles = { -- Top, base, right, left, front, back
|
||||||
@ -48,12 +61,12 @@ minetest.register_node("tubelib2:tubeS", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
local t = minetest.get_us_time()
|
--local t = minetest.get_us_time()
|
||||||
if not Tube:after_place_tube(pos, placer, pointed_thing) then
|
if not Tube:after_place_tube(pos, placer, pointed_thing) then
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
print("place time", minetest.get_us_time() - t)
|
--print("place time", minetest.get_us_time() - t)
|
||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -185,18 +198,6 @@ minetest.register_node("tubelib2:junction", {
|
|||||||
Tube:after_dig_node(pos)
|
Tube:after_dig_node(pos)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
tubelib2_on_update = function(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
|
|
||||||
local node = minetest.get_node(peer_pos)
|
|
||||||
print(S(pos).." to the "..sdir..": Connected with "..node.name)
|
|
||||||
else
|
|
||||||
print(S(pos).." to the "..sdir..": Connected with "..S(peer_pos))
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
|
|
||||||
paramtype2 = "facedir", -- important!
|
paramtype2 = "facedir", -- important!
|
||||||
on_rotate = screwdriver.disallow, -- important!
|
on_rotate = screwdriver.disallow, -- important!
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
@ -294,8 +295,9 @@ local function remove_tube(itemstack, placer, pointed_thing)
|
|||||||
Tube:tool_remove_tube(pos, "default_break_glass")
|
Tube:tool_remove_tube(pos, "default_break_glass")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
local dir = (minetest.dir_to_facedir(placer:get_look_dir()) % 4) + 1
|
||||||
minetest.chat_send_player(placer:get_player_name(),
|
minetest.chat_send_player(placer:get_player_name(),
|
||||||
"[Tool Help]\n"..
|
"[Tool Help] dir="..dir.."\n"..
|
||||||
" left: remove node\n"..
|
" left: remove node\n"..
|
||||||
" right: repair tube line\n")
|
" right: repair tube line\n")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user