mirror of
https://github.com/joe7575/tubelib2.git
synced 2024-10-04 00:43:14 +02:00
v1.1 API function 'switch_tube_line' added, secondary node placement bugfix
This commit is contained in:
parent
5132cd33aa
commit
9a79b65b3c
@ -72,3 +72,4 @@ Textures: CC0
|
||||
- 2019-01-11 v0.8 * dir_to_facedir bugfix
|
||||
- 2019-02-09 v0.9 * storage.lua added, code partly restructured
|
||||
- 2019-02-17 v1.0 * released
|
||||
- 2019-03-02 v1.1 * API function added, place secondary node bugfix
|
||||
|
@ -140,7 +140,7 @@ function Tube:update_after_place_node(pos, dirs)
|
||||
dirs = dirs or self.dirs_to_check
|
||||
for _,dir in ipairs(dirs) do
|
||||
local npos, d1, d2, num = self:add_tube_dir(pos, dir)
|
||||
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and tValidNum[num]then
|
||||
if npos and self.valid_dirs[d1] and self.valid_dirs[d2] and num and num < 2 then
|
||||
self.clbk_after_place_tube(self:get_tube_data(npos, d1, d2, num))
|
||||
lRes[#lRes+1] = dir
|
||||
end
|
||||
@ -219,3 +219,25 @@ function Tube:replace_nodes(pos1, pos2, dir1, dir2)
|
||||
self.clbk_after_place_tube(self:get_tube_data(pos2, dir1, dir2, 1))
|
||||
end
|
||||
|
||||
|
||||
function Tube:switch_nodes(pos, dir, state)
|
||||
pos = get_pos(pos, dir)
|
||||
local old_dir = dir
|
||||
while pos do
|
||||
local param2 = self:get_primary_node_param2(pos)
|
||||
if param2 then
|
||||
local dir1, dir2, num_conn = self:decode_param2(pos, param2)
|
||||
self.clbk_after_place_tube(self:get_tube_data(pos, dir1, dir2, num_conn, state))
|
||||
print(S(pos), param2, dir1, dir2, num_conn)
|
||||
if dir1 == Turn180Deg[old_dir] then
|
||||
pos = get_pos(pos, dir2)
|
||||
old_dir = dir2
|
||||
else
|
||||
pos = get_pos(pos, dir1)
|
||||
old_dir = dir1
|
||||
end
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -190,9 +190,9 @@ function Tube:get_node(pos, dir)
|
||||
end
|
||||
|
||||
-- format and return given data as table
|
||||
function Tube:get_tube_data(pos, dir1, dir2, num_tubes)
|
||||
function Tube:get_tube_data(pos, dir1, dir2, num_tubes, state)
|
||||
local param2, tube_type = self:encode_param2(dir1, dir2, num_tubes)
|
||||
return pos, param2, tube_type, num_tubes
|
||||
return pos, param2, tube_type, num_tubes, state
|
||||
end
|
||||
|
||||
-- Return pos for a primary_node and true if num_conn < 2, else false
|
||||
@ -205,6 +205,16 @@ function Tube:friendly_primary_node(pos, dir)
|
||||
end
|
||||
end
|
||||
|
||||
function Tube:vector_to_dir(v)
|
||||
if v.y > 0 then
|
||||
return 6
|
||||
elseif v.y < 0 then
|
||||
return 5
|
||||
else
|
||||
return minetest.dir_to_facedir(v) + 1
|
||||
end
|
||||
end
|
||||
|
||||
-- Check all 6 possible positions for known nodes considering preferred_pos
|
||||
-- and the players fdir and return dir1, dir2 and the number of tubes to connect to (0..2).
|
||||
function Tube:determine_tube_dirs(pos, preferred_pos, fdir)
|
||||
@ -217,14 +227,7 @@ function Tube:determine_tube_dirs(pos, preferred_pos, fdir)
|
||||
local _, friendly = self:friendly_primary_node(preferred_pos)
|
||||
if friendly then
|
||||
local v = vector.direction(pos, preferred_pos)
|
||||
local dir1
|
||||
if v.y > 0 then
|
||||
dir1 = 6
|
||||
elseif v.y < 0 then
|
||||
dir1 = 5
|
||||
else
|
||||
dir1 = minetest.dir_to_facedir(v) + 1
|
||||
end
|
||||
local dir1 = self:vector_to_dir(v)
|
||||
local dir2 = Turn180Deg[fdir]
|
||||
return dir1, dir2, 1
|
||||
end
|
||||
|
10
tube_api.lua
10
tube_api.lua
@ -13,7 +13,7 @@
|
||||
]]--
|
||||
|
||||
-- Version for compatibility checks, see readme.md/history
|
||||
tubelib2.version = 0.9
|
||||
tubelib2.version = 1.1
|
||||
|
||||
-- for lazy programmers
|
||||
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
@ -46,6 +46,7 @@ local Dir6dToVector = tubelib2.Dir6dToVector
|
||||
local function get_pos(pos, dir)
|
||||
return vector.add(pos, Dir6dToVector[dir or 0])
|
||||
end
|
||||
tubelib2.get_pos = get_pos
|
||||
|
||||
local function update1(self, pos, dir)
|
||||
local fpos,fdir = self:walk_tube_line(pos, dir)
|
||||
@ -331,7 +332,7 @@ function Tube:replace_tube_line(pos1, pos2)
|
||||
(((pos1.z == pos2.z) and 1) or 0)
|
||||
if check == 2 then
|
||||
local v = vector.direction(pos1, pos2)
|
||||
local dir1 = minetest.dir_to_facedir(v, true) + 1
|
||||
local dir1 = self:vector_to_dir(v)
|
||||
local dir2 = Turn180Deg[dir1]
|
||||
|
||||
self:replace_nodes(pos1, pos2, dir1, dir2)
|
||||
@ -339,3 +340,8 @@ function Tube:replace_tube_line(pos1, pos2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Used to change the tube nodes texture (e.g. on/off state)
|
||||
function Tube:switch_tube_line(pos, dir, state)
|
||||
self:switch_nodes(pos, dir, state)
|
||||
end
|
Loading…
Reference in New Issue
Block a user