Change left,right and back vectors to matrix math results with no branching

This commit is contained in:
teknomunk 2024-02-13 15:28:00 +00:00
parent 2bb1aa7241
commit 669d9d0556
1 changed files with 5 additions and 15 deletions

View File

@ -76,16 +76,10 @@ function mcl_minecarts:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
local cur local cur
local left_check, right_check = true, true local left_check, right_check = true, true
-- Check left and right -- Calculate left, right and back
local left = vector.new(0, 0, 0) local left = vector.new(-dir.z, dir.y, dir.x)
local right = vector.new(0, 0, 0) local right = vector.new( dir.z, dir.y, -dir.x)
if dir.z ~= 0 and dir.x == 0 then local back = vector.new(-dir.x, dir.y, -dir.z)
left.x = -dir.z
right.x = dir.z
elseif dir.x ~= 0 and dir.z == 0 then
left.z = dir.x
right.z = -dir.x
end
if ctrl then if ctrl then
if old_switch == 1 then if old_switch == 1 then
@ -132,11 +126,7 @@ function mcl_minecarts:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
end end
-- Backwards -- Backwards
if not old_switch then if not old_switch then
cur = mcl_minecarts:check_front_up_down(pos, vector.new( cur = mcl_minecarts:check_front_up_down(pos, back, true, railtype)
-dir.x,
dir.y,
-dir.z
), true, railtype)
if cur then if cur then
return cur return cur
end end