From 9b647b082370d54d9952169f2266e6400d2a6caa Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 28 Dec 2024 20:02:52 -0600 Subject: [PATCH] Add curve->tee and tee->cross conversion logic, fix typo --- mods/ENTITIES/mcl_minecarts/functions.lua | 19 +++++++++++++++---- mods/ENTITIES/mcl_minecarts/rails.lua | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/mods/ENTITIES/mcl_minecarts/functions.lua b/mods/ENTITIES/mcl_minecarts/functions.lua index 1305a87a1..d1099c6fd 100644 --- a/mods/ENTITIES/mcl_minecarts/functions.lua +++ b/mods/ENTITIES/mcl_minecarts/functions.lua @@ -283,7 +283,6 @@ local function bend_straight_rail(pos, towards) local dir2_connected = is_rail_end_connected(pos + dir2, dir1) if dir1_connected and dir2_connected then return end - -- TODO: bend the rail local connections = { vector.direction(pos, towards), } @@ -307,8 +306,6 @@ local function bend_straight_rail(pos, towards) end local function update_rail_connections(pos, opt) - local ignore_neighbor_connections = opt and opt.ignore_neighbor_connections - local node = minetest.get_node(pos) local nodedef = minetest.registered_nodes[node.name] if not nodedef or not nodedef._mcl_minecarts then return end @@ -333,7 +330,7 @@ local function update_rail_connections(pos, opt) for i = 1,#CONNECTIONS do local dir = CONNECTIONS[i] local neighbor = vector.add(pos, dir) - make_sloped_if_straight( vector.offset(neighbor, 0, -1, 0), dir ) + make_sloped_if_straight(vector.offset(neighbor, 0, -1, 0), dir) end apply_connection_rules(node, nodedef, pos, rules, connections) @@ -350,6 +347,20 @@ local function update_rail_connections(pos, opt) end end + -- Check if the open end of this rail runs into a corner or a tee and convert that node into a tee or a cross + local neighbors = {} + for i=1,#CONNECTIONS do + local dir = CONNECTIONS[i] + if is_connection(pos, dir) then + local other_pos = pos - dir + local other_node = core.get_node(other_pos) + local other_node_def = core.registered_nodes[other_node.name] + local railtype = get_path(other_node_def, "_mcl_minecarts","railtype") + if (not opt or opt.convert_neighbors ~= false) and railtype == "corner" or railtype == "tee" then + update_rail_connections(other_pos, {convert_neighbors = false}) + end + end + end end mod.update_rail_connections = update_rail_connections diff --git a/mods/ENTITIES/mcl_minecarts/rails.lua b/mods/ENTITIES/mcl_minecarts/rails.lua index 4ce80ff0d..3163763f5 100644 --- a/mods/ENTITIES/mcl_minecarts/rails.lua +++ b/mods/ENTITIES/mcl_minecarts/rails.lua @@ -20,7 +20,7 @@ local south = mod.south local east = mod.east local west = mod.west ---- Rail direction Handleres +--- Rail direction Handlers local function rail_dir_straight(pos, dir, node) dir = vector.new(dir) dir.y = 0