From e4eb38db9c7b40c45774c3250ce89251733b1e81 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Mon, 11 Mar 2024 20:14:11 +0000 Subject: [PATCH] Fix diagonal movement --- mods/ENTITIES/mcl_minecarts/functions.lua | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/mods/ENTITIES/mcl_minecarts/functions.lua b/mods/ENTITIES/mcl_minecarts/functions.lua index 9ea7de40a..48392cbee 100644 --- a/mods/ENTITIES/mcl_minecarts/functions.lua +++ b/mods/ENTITIES/mcl_minecarts/functions.lua @@ -88,20 +88,33 @@ local rail_checks = { { -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 local diagonal_convert = { - nw = vector.new( 0,0, 1), -- north - ne = vector.new( 1,0, 0), -- east - se = vector.new( 0,0,-1), -- south - sw = vector.new(-1,0, 0), -- west + nw = west, + ne = north, + se = east, + sw = south, } function mcl_minecarts:get_rail_direction(pos_, dir, ctrl, old_switch, railtype) local pos = vector.round(pos_) -- Diagonal conversion + local checks = rail_checks if dir.x ~= 0 and dir.z ~= 0 then dir = diagonal_convert[ mcl_minecarts:name_from_dir(dir, false) ] + checks = rail_checks_diagonal end -- 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) -- 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_pos = pos + check_dir if mcl_minecarts:is_rail(check_pos,railtype) then