forked from VoxeLibre/VoxeLibre
Fix diagonal movement
This commit is contained in:
parent
b4a0ae9c56
commit
e4eb38db9c
|
@ -88,20 +88,33 @@ local rail_checks = {
|
||||||
{ -1, 0, 0 }, -- backwards
|
{ -1, 0, 0 }, -- backwards
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local rail_checks_diagonal = {
|
||||||
|
{ 1, 1, 0 }, -- forward along diagonal
|
||||||
|
{ 1, 0, 0 }, -- left
|
||||||
|
{ 0, 1, 0 }, -- right
|
||||||
|
}
|
||||||
|
|
||||||
|
local north = vector.new(0,0,1)
|
||||||
|
local south = vector.new(0,0,-1)
|
||||||
|
local east = vector.new(1,0,0)
|
||||||
|
local west = vector.new(-1,0,0)
|
||||||
|
|
||||||
-- Rotate diagonal directions 45 degrees clockwise
|
-- Rotate diagonal directions 45 degrees clockwise
|
||||||
local diagonal_convert = {
|
local diagonal_convert = {
|
||||||
nw = vector.new( 0,0, 1), -- north
|
nw = west,
|
||||||
ne = vector.new( 1,0, 0), -- east
|
ne = north,
|
||||||
se = vector.new( 0,0,-1), -- south
|
se = east,
|
||||||
sw = vector.new(-1,0, 0), -- west
|
sw = south,
|
||||||
}
|
}
|
||||||
|
|
||||||
function mcl_minecarts:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
|
function mcl_minecarts:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
|
||||||
local pos = vector.round(pos_)
|
local pos = vector.round(pos_)
|
||||||
|
|
||||||
-- Diagonal conversion
|
-- Diagonal conversion
|
||||||
|
local checks = rail_checks
|
||||||
if dir.x ~= 0 and dir.z ~= 0 then
|
if dir.x ~= 0 and dir.z ~= 0 then
|
||||||
dir = diagonal_convert[ mcl_minecarts:name_from_dir(dir, false) ]
|
dir = diagonal_convert[ mcl_minecarts:name_from_dir(dir, false) ]
|
||||||
|
checks = rail_checks_diagonal
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Calculate coordinate space
|
-- Calculate coordinate space
|
||||||
|
@ -109,7 +122,7 @@ function mcl_minecarts:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
|
||||||
local up = vector.new(0,1,0)
|
local up = vector.new(0,1,0)
|
||||||
|
|
||||||
-- Perform checks
|
-- Perform checks
|
||||||
for _,check in ipairs(rail_checks) do
|
for _,check in ipairs(checks) do
|
||||||
local check_dir = dir * check[1] + right * check[2] + up * check[3]
|
local check_dir = dir * check[1] + right * check[2] + up * check[3]
|
||||||
local check_pos = pos + check_dir
|
local check_pos = pos + check_dir
|
||||||
if mcl_minecarts:is_rail(check_pos,railtype) then
|
if mcl_minecarts:is_rail(check_pos,railtype) then
|
||||||
|
|
Loading…
Reference in New Issue