From e746556e09f1b0ab997aff2c7e8d5183771412d6 Mon Sep 17 00:00:00 2001 From: nixnoxus Date: Sun, 24 Dec 2023 01:28:58 +0100 Subject: [PATCH] local plane_adjacents ... --- mods/ENTITIES/mcl_minecarts/functions.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/mods/ENTITIES/mcl_minecarts/functions.lua b/mods/ENTITIES/mcl_minecarts/functions.lua index d1e25ea84..1792e9252 100644 --- a/mods/ENTITIES/mcl_minecarts/functions.lua +++ b/mods/ENTITIES/mcl_minecarts/functions.lua @@ -136,23 +136,25 @@ function mcl_minecarts:get_rail_direction(pos_, dir, ctrl, old_switch, railtype) return {x=0, y=0, z=0} end +local plane_adjacents = { + vector.new(-1,0,0), + vector.new(1,0,0), + vector.new(0,0,-1), + vector.new(0,0,1), +} + function mcl_minecarts:get_start_direction(pos) - local r = {{x=-1, y= 0, z= 0}, - {x= 1, y= 0, z= 0}, - {x= 0, y= 0, z=-1}, - {x= 0, y= 0, z= 1}, - } local dir local i = 0 - while (not dir and i < #r) do + while (not dir and i < #plane_adjacents) do i = i+1 - local node = minetest.get_node_or_nil(vector.add(pos, r[i])) + local node = minetest.get_node_or_nil(vector.add(pos, plane_adjacents[i])) if node ~= nil and minetest.get_item_group(node.name, "rail") == 0 and minetest.get_item_group(node.name, "solid") == 1 and minetest.get_item_group(node.name, "opaque") == 1 then - dir = mcl_minecarts:check_front_up_down(pos, vector.multiply(r[i], -1), true) + dir = mcl_minecarts:check_front_up_down(pos, vector.multiply(plane_adjacents[i], -1), true) end end return dir