mirror of
https://github.com/joe7575/tubelib2.git
synced 2024-07-07 08:25:20 +02:00
Extend the 'node.param2' support for all 24 possible values
This commit is contained in:
parent
4651811d95
commit
fbe7d2fe22
@ -55,7 +55,7 @@ optional: intllib
|
||||
|
||||
|
||||
## License
|
||||
Copyright (C) 2017-2021 Joachim Stolberg
|
||||
Copyright (C) 2017-2022 Joachim Stolberg
|
||||
Code: Licensed under the GNU LGPL version 2.1 or later.
|
||||
See LICENSE.txt and http://www.gnu.org/licenses/lgpl-2.1.txt
|
||||
Textures: CC0
|
||||
@ -89,5 +89,6 @@ Textures: CC0
|
||||
- 2020-05-31 v1.9 * Generator function 'get_tube_line' added, storage improvements
|
||||
- 2021-01-23 v2.0 * Add functions for easy & fast 'valid side' checking (PR #8)
|
||||
- 2021-05-24 v2.1 * Add API functions 'register_on_tube_update2'
|
||||
- 2022-01-05 v2.2 * Extend the 'node.param2' support for all 24 possible values
|
||||
|
||||
|
||||
|
36
tube_api.lua
36
tube_api.lua
@ -13,7 +13,7 @@
|
||||
]]--
|
||||
|
||||
-- Version for compatibility checks, see readme.md/history
|
||||
tubelib2.version = 2.1
|
||||
tubelib2.version = 2.2
|
||||
|
||||
-- for lazy programmers
|
||||
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
@ -31,23 +31,31 @@ function tubelib2.dir_to_string(dir)
|
||||
end
|
||||
|
||||
-- Relative directions, dependant on orientation (param2)
|
||||
local DirToSide = {"B", "R", "F", "L", "D", "U"}
|
||||
local DirToSide = {
|
||||
-- param2 (0 to 23)
|
||||
{[0]="B","L","F","R", "U","U","U","U", "D","D","D","D", "B","L","F","R", "B","L","F","R", "B","L","F","R",}, -- dir = 1
|
||||
{[0]="R","B","L","F", "R","B","L","F", "R","B","L","F", "U","U","U","U", "D","D","D","D", "L","F","R","B",}, -- dir = 2
|
||||
{[0]="F","R","B","L", "D","D","D","D", "U","U","U","U", "F","R","B","L", "F","R","B","L", "F","R","B","L",}, -- dir = 3
|
||||
{[0]="L","F","R","B", "L","F","R","B", "L","F","R","B", "D","D","D","D", "U","U","U","U", "R","B","L","F",}, -- dir = 4
|
||||
{[0]="D","D","D","D", "B","L","F","R", "F","R","B","L", "R","B","L","F", "L","F","R","B", "U","U","U","U",}, -- dir = 5
|
||||
{[0]="U","U","U","U", "F","R","B","L", "B","L","F","R", "L","F","R","B", "R","B","L","F", "D","D","D","D",}, -- dir = 6
|
||||
}
|
||||
|
||||
local SideToDir = {B={}, R={}, F={}, L={}, D={}, U={}}
|
||||
|
||||
for param2 = 0,23 do
|
||||
for dir = 1,6 do
|
||||
local side = DirToSide[dir][param2]
|
||||
SideToDir[side][param2] = dir
|
||||
end
|
||||
end
|
||||
|
||||
function tubelib2.dir_to_side(dir, param2)
|
||||
if dir < 5 then
|
||||
dir = (((dir - 1) - (param2 % 4)) % 4) + 1
|
||||
return DirToSide[dir][param2]
|
||||
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
|
||||
return SideToDir[side][param2]
|
||||
end
|
||||
|
||||
|
||||
@ -234,7 +242,7 @@ local function invert_booleans(tab)
|
||||
end
|
||||
return inversion
|
||||
end
|
||||
local valid_sides_default_true = Tbl(DirToSide)
|
||||
local valid_sides_default_true = Tbl({"B", "R", "F", "L", "D", "U"})
|
||||
local valid_sides_default_false = invert_booleans(valid_sides_default_true)
|
||||
local function complete_valid_sides(valid_sides, existing_defaults)
|
||||
local valid_sides_complete = {}
|
||||
|
Loading…
Reference in New Issue
Block a user