1
0
Fork 0

Convert curved rails direction code to use fourdir

This commit is contained in:
teknomunk 2024-04-28 05:52:16 +00:00
parent 120af0f434
commit a2bb88bb2e
1 changed files with 28 additions and 18 deletions

View File

@ -47,32 +47,42 @@ local function rail_dir_sloped(pos, dir, node)
end end
local function rail_dir_curve(pos, dir, node) local function rail_dir_curve(pos, dir, node)
dir = vector.new(dir.x, 0, dir.z) dir = vector.new(dir.x, 0, dir.z)
local dir_fourdir = minetest.dir_to_fourdir(dir)
-- Fourdir
-- 0 = north
-- 1 = east
-- 2 = south
-- 3 = west
local new_fourdir = 0
if node.param2 == 0 then -- north if node.param2 == 0 then -- north
-- South and East -- South and East
if vector.equals(dir, south) then return south end if dir_fourdir == 0 then new_fourdir = 1 end
if vector.equals(dir, north) then return east end if dir_fourdir == 1 then new_fourdir = 1 end
if vector.equals(dir, west) then return south end if dir_fourdir == 2 then new_fourdir = 2 end
if vector.equals(dir, east) then return east end if dir_fourdir == 3 then new_fourdir = 2 end
elseif node.param2 == 1 then -- east elseif node.param2 == 1 then -- east
-- South and West -- South and West
if vector.equals(dir, south) then return south end if dir_fourdir == 1 then new_fourdir = 2 end
if vector.equals(dir, north) then return west end if dir_fourdir == 2 then new_fourdir = 2 end
if vector.equals(dir, west) then return west end if dir_fourdir == 3 then new_fourdir = 3 end
if vector.equals(dir, east) then return south end if dir_fourdir == 0 then new_fourdir = 3 end
elseif node.param2 == 2 then elseif node.param2 == 2 then -- south
-- North and West -- North and West
if vector.equals(dir, south) then return west end if dir_fourdir == 2 then new_fourdir = 3 end
if vector.equals(dir, north) then return north end if dir_fourdir == 3 then new_fourdir = 3 end
if vector.equals(dir, west) then return west end if dir_fourdir == 0 then new_fourdir = 0 end
if vector.equals(dir, east) then return north end if dir_fourdir == 1 then new_fourdir = 0 end
elseif node.param2 == 3 then elseif node.param2 == 3 then -- west
-- North and East -- North and East
if vector.equals(dir, south) then return east end if dir_fourdir == 3 then new_fourdir = 0 end
if vector.equals(dir, north) then return north end if dir_fourdir == 0 then new_fourdir = 0 end
if vector.equals(dir, west) then return north end if dir_fourdir == 1 then new_fourdir = 1 end
if vector.equals(dir, east) then return east end if dir_fourdir == 2 then new_fourdir = 1 end
end end
return minetest.fourdir_to_dir(new_fourdir)
end end