mirror of
https://github.com/joe7575/tubelib2.git
synced 2024-12-01 03:43:45 +01:00
v0.4 - bugfixes
This commit is contained in:
parent
1135b340e4
commit
fd2599f676
@ -96,6 +96,21 @@ function Tube:get_meta(pos, dir)
|
||||
return self:repair_tube_line(pos, dir)
|
||||
end
|
||||
|
||||
-- Like get_meta(), but repair data if necessary
|
||||
function Tube:repair_meta(pos, dir)
|
||||
local npos = vector.add(pos, Dir6dToVector[dir or 0])
|
||||
local meta = M(npos)
|
||||
local peer_pos = meta:get_string("peer_pos")
|
||||
local peer_dir = meta:get_int("peer_dir")
|
||||
if peer_pos ~= "" then
|
||||
return P(peer_pos), peer_dir
|
||||
end
|
||||
peer_pos, peer_dir = self:repair_tube_line(pos, dir)
|
||||
self:add_meta(npos, peer_pos, peer_dir)
|
||||
return peer_pos, peer_dir
|
||||
end
|
||||
|
||||
|
||||
function Tube:get_oldmeta(pos, dir, oldmetadata)
|
||||
if oldmetadata.fields and oldmetadata.fields.peer_pos then
|
||||
return P(oldmetadata.fields.peer_pos), tonumber(oldmetadata.fields.peer_dir)
|
||||
@ -135,10 +150,10 @@ function Tube:repair_tube_line(pos, dir)
|
||||
return self:get_next_teleport_node(pos, dir)
|
||||
end
|
||||
|
||||
print("repair_tube_line")
|
||||
local cnt = 0
|
||||
if not dir then return pos, dir, cnt end
|
||||
while cnt <= self.max_tube_length do
|
||||
--if cnt > 1 then M(pos):from_table(nil) end
|
||||
local new_pos, new_dir = repair_next_tube(self, pos, dir)
|
||||
if not new_dir then break end
|
||||
pos, dir = new_pos, new_dir
|
||||
@ -231,7 +246,7 @@ function Tube:update_after_place_tube(pos, placer, pointed_thing)
|
||||
self.clbk_after_place_tube(self:tube_data_to_table(npos, d1, d2, num))
|
||||
end
|
||||
end
|
||||
return true, dir1, dir2
|
||||
return true, dir1, dir2, num_tubes
|
||||
end
|
||||
|
||||
function Tube:update_after_dig_tube(pos, param2)
|
||||
|
13
tube_api.lua
13
tube_api.lua
@ -71,7 +71,7 @@ function Tube:after_place_node(pos, dirs)
|
||||
-- [s][f]----[n] x
|
||||
-- s..secondary, f..far, n..near, x..node to be placed
|
||||
for _,dir in ipairs(self:update_after_place_node(pos, dirs)) do
|
||||
local fpos,fdir = self:get_meta(pos, dir)
|
||||
local fpos,fdir = self:repair_meta(pos, dir)
|
||||
local npos, ndir = self:get_pos(pos, dir)
|
||||
self:update_secondary_node(fpos,fdir, npos,ndir)
|
||||
self:update_secondary_node(npos,ndir, fpos,fdir)
|
||||
@ -83,8 +83,8 @@ end
|
||||
function Tube:after_place_tube(pos, placer, pointed_thing)
|
||||
-- [s1][f1]----[n1] x [n2]-----[f2][s2]
|
||||
-- s..secondary, f..far, n..near, x..node to be placed
|
||||
local res,dir1,dir2 = self:update_after_place_tube(pos, placer, pointed_thing)
|
||||
if res then
|
||||
local res,dir1,dir2,cnt = self:update_after_place_tube(pos, placer, pointed_thing)
|
||||
if res and cnt > 0 then -- other nodes around?
|
||||
local fpos1,fdir1 = self:del_meta(pos, dir1)
|
||||
local fpos2,fdir2 = self:del_meta(pos, dir2)
|
||||
self:add_meta(fpos1, fpos2,fdir2)
|
||||
@ -126,8 +126,13 @@ end
|
||||
-- The returned pos is the destination position, dir
|
||||
-- is the direction into the destination node.
|
||||
function Tube:get_connected_node_pos(pos, dir)
|
||||
local fpos,fdir = self:get_meta(pos, dir)
|
||||
local fpos,fdir = self:repair_meta(pos, dir)
|
||||
local npos,ndir = self:get_pos(fpos,fdir)
|
||||
-- only one tube with wrong dir info?
|
||||
if vector.equals(pos, npos) then
|
||||
fpos,fdir = self:del_meta(pos, dir)
|
||||
return self:get_pos(fpos,fdir)
|
||||
end
|
||||
return npos, dir
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user