From abde0b6ebba9bcd6710f736d84a334cf5018fb2f Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sun, 5 Apr 2020 10:15:30 +0200 Subject: [PATCH] bugfix --- internal2.lua | 15 +++++++++------ tube_api.lua | 25 +++++++++++++------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/internal2.lua b/internal2.lua index 2a02031..dffbfb0 100644 --- a/internal2.lua +++ b/internal2.lua @@ -160,9 +160,9 @@ end function Tube:get_next_tube(pos, dir) local param2, npos = self:get_primary_node_param2(pos, dir) if param2 then - local val = Param2ToDir[param2 % 32] + local val = Param2ToDir[param2 % 32] or 0 local dir1, dir2 = math.floor(val / 10), val % 10 - local num_conn = math.floor(param2 / 32) + local num_conn = math.floor(param2 / 32) or 0 if Turn180Deg[dir] == dir1 then return npos, dir2, num_conn else @@ -174,11 +174,14 @@ end -- Return param2 and tube type ("A"/"S") function Tube:encode_param2(dir1, dir2, num_conn) - if dir1 > dir2 then - dir1, dir2 = dir2, dir1 + if dir1 and dir2 and num_conn then + if dir1 > dir2 then + dir1, dir2 = dir2, dir1 + end + local param2, _type = unpack(DirToParam2[dir1 * 10 + dir2] or {0, "S"}) + return (num_conn * 32) + param2, _type end - local param2, _type = unpack(DirToParam2[dir1 * 10 + dir2] or {0, "S"}) - return (num_conn * 32) + param2, _type + return 0, "S" end diff --git a/tube_api.lua b/tube_api.lua index 59c0c09..e4028ce 100644 --- a/tube_api.lua +++ b/tube_api.lua @@ -120,7 +120,6 @@ local function update_secondary_nodes_after_node_placed(self, pos, dirs) 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 @@ -237,17 +236,19 @@ function Tube:after_dig_tube(pos, oldnode) -- s..secondary, f..far, n..near, x..node to be removed -- update tubes - local dir1, dir2 = self:update_after_dig_tube(pos, oldnode.param2) - if dir1 then update1(self, pos, dir1) end - if dir2 then update1(self, pos, dir2) end - - -- Update secondary nodes, if right beside - dir1, dir2 = self:decode_param2(pos, oldnode.param2) - local npos1,ndir1 = get_pos(pos, dir1),Turn180Deg[dir1] - local npos2,ndir2 = get_pos(pos, dir2),Turn180Deg[dir2] - self:del_from_cache(npos1,ndir1) - self:update_secondary_node(npos1,ndir1) - self:update_secondary_node(npos2,ndir2) + if oldnode and oldnode.param2 then + local dir1, dir2 = self:update_after_dig_tube(pos, oldnode.param2) + if dir1 then update1(self, pos, dir1) end + if dir2 then update1(self, pos, dir2) end + + -- Update secondary nodes, if right beside + dir1, dir2 = self:decode_param2(pos, oldnode.param2) + local npos1,ndir1 = get_pos(pos, dir1),Turn180Deg[dir1] + local npos2,ndir2 = get_pos(pos, dir2),Turn180Deg[dir2] + self:del_from_cache(npos1,ndir1) + self:update_secondary_node(npos1,ndir1) + self:update_secondary_node(npos2,ndir2) + end end