mirror of
https://github.com/joe7575/tubelib2.git
synced 2024-11-28 10:23:45 +01:00
Implemented new method of defining valid faces through the secondary node registration
This commit is contained in:
parent
132d7568d8
commit
5232d1a3af
@ -121,12 +121,12 @@ function Tube:get_secondary_node(pos, dir)
|
||||
local npos = vector.add(pos, Dir6dToVector[dir or 0])
|
||||
local node = self:get_node_lvm(npos)
|
||||
if self.secondary_node_names[node.name] then
|
||||
local valid_dir_string = minetest.get_meta(npos):get_string('valid_dirs')
|
||||
local valid_dirs = self.valid_dirs
|
||||
if valid_dir_string and valid_dir_string ~= "" then
|
||||
valid_dirs = minetest.deserialize(valid_dir_string)
|
||||
local is_valid_dir = nil
|
||||
if dir ~= nil then
|
||||
local side = tubelib2.dir_to_side(Turn180Deg[dir], node.param2)
|
||||
is_valid_dir = self.secondary_node_names[node.name][side] or false
|
||||
end
|
||||
return node, npos, valid_dirs[Turn180Deg[dir]] or false
|
||||
return node, npos, is_valid_dir
|
||||
end
|
||||
end
|
||||
|
||||
|
35
tube_api.lua
35
tube_api.lua
@ -23,12 +23,34 @@ local M = minetest.get_meta
|
||||
local MP = minetest.get_modpath("tubelib2")
|
||||
local I,_ = dofile(MP.."/intllib.lua")
|
||||
|
||||
-- Cardinal directions, regardless of orientation
|
||||
local Dir2Str = {"north", "east", "south", "west", "down", "up"}
|
||||
|
||||
function tubelib2.dir_to_string(dir)
|
||||
return Dir2Str[dir]
|
||||
end
|
||||
|
||||
-- Relative directions, dependant on orientation (param2)
|
||||
local DirToSide = {"B", "R", "F", "L", "D", "U"}
|
||||
|
||||
function tubelib2.dir_to_side(dir, param2)
|
||||
if dir < 5 then
|
||||
dir = (((dir - 1) - (param2 % 4)) % 4) + 1
|
||||
end
|
||||
return DirToSide[dir]
|
||||
end
|
||||
|
||||
local SideToDir = {B=1, R=2, F=3, L=4, D=5, U=6}
|
||||
|
||||
function tubelib2.side_to_dir(side, param2)
|
||||
local dir = SideToDir[side]
|
||||
if dir < 5 then
|
||||
dir = (((dir - 1) + (param2 % 4)) % 4) + 1
|
||||
end
|
||||
return dir
|
||||
end
|
||||
|
||||
|
||||
local function Tbl(list)
|
||||
local tbl = {}
|
||||
for _,item in ipairs(list) do
|
||||
@ -193,10 +215,19 @@ function Tube:new(attr)
|
||||
return o
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- Register (foreign) tubelib compatible nodes.
|
||||
function Tube:add_secondary_node_names(names)
|
||||
local valid_sides_default = {B=true, R=true, F=true, L=true, D=true, U=true}
|
||||
function Tube:add_secondary_node_names(names, valid_sides)
|
||||
local valid_sides_complete = valid_sides or {}
|
||||
for side, defaultValue in pairs(valid_sides_default) do
|
||||
if valid_sides_complete[side] == nil then
|
||||
valid_sides_complete[side] = defaultValue
|
||||
end
|
||||
end
|
||||
for _,name in ipairs(names) do
|
||||
self.secondary_node_names[name] = true
|
||||
self.secondary_node_names[name] = valid_sides_complete
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user