From 75f394e5ab049c2da5e9d01a60fce0a83e65063a Mon Sep 17 00:00:00 2001 From: teknomunk Date: Fri, 29 Mar 2024 19:53:13 +0000 Subject: [PATCH] Add sloped rail --- .../mcl_minecarts/models/sloped_track.obj | 15 +++++++ mods/ENTITIES/mcl_minecarts/rails.lua | 44 ++++++++++++++++++- .../ENTITIES/mcl_minecarts/rails/standard.lua | 6 ++- 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 mods/ENTITIES/mcl_minecarts/models/sloped_track.obj diff --git a/mods/ENTITIES/mcl_minecarts/models/sloped_track.obj b/mods/ENTITIES/mcl_minecarts/models/sloped_track.obj new file mode 100644 index 000000000..86edb4b58 --- /dev/null +++ b/mods/ENTITIES/mcl_minecarts/models/sloped_track.obj @@ -0,0 +1,15 @@ +# hand-made Wavefront .OBJ file for sloped rail +mtllib mcl_minecarts_rail.mtl +o sloped_rail.001 +v -0.500000 -0.500000 -0.500000 +v -0.500000 0.500000 0.500000 +v 0.500000 0.500000 0.500000 +v 0.500000 -0.500000 -0.500000 +vt 1.000000 0.000000 +vt 1.000000 1.000000 +vt 0.000000 1.000000 +vt 0.000000 0.000000 +vn 0.707106 0.707106 0.000000 +usemtl None +s off +f 1/1/1 2/2/1 3/3/1 4/4/1 diff --git a/mods/ENTITIES/mcl_minecarts/rails.lua b/mods/ENTITIES/mcl_minecarts/rails.lua index 970598971..3ec8980b2 100644 --- a/mods/ENTITIES/mcl_minecarts/rails.lua +++ b/mods/ENTITIES/mcl_minecarts/rails.lua @@ -80,7 +80,6 @@ local function register_rail_v2(itemstring, def) if def.groups then table_merge(groups, def.groups) end def.groups = groups - -- Build the node definition local ndef = { drawtype = "nodebox", @@ -106,6 +105,49 @@ local function register_rail_v2(itemstring, def) end mod.register_rail = register_rail_v2 + +local function register_rail_sloped(itemstring, def) + assert(def.tiles) + + -- Build rail groups + local groups = table.copy(RAIL_DEFAULT_GROUPS) + if def.groups then table_merge(groups, def.groups) end + def.groups = groups + + -- Build the node definition + local ndef = table.copy(RAIL_DEFAULTS) + table_merge(ndef,{ + drawtype = "mesh", + mesh = "sloped_track.obj", + collision_box = { + type = "fixed", + fixed = { + { -0.5, -0.5, -0.5, 0.5, 0.0, 0.5 }, + { -0.5, 0.0, 0.0, 0.5, 0.5, 0.5 } + } + }, + selection_box = { + type = "fixed", + fixed = { + { -0.5, -0.5, -0.5, 0.5, 0.0, 0.5 }, + { -0.5, 0.0, 0.0, 0.5, 0.5, 0.5 } + } + } + }) + table_merge(ndef, def) + + -- Add sensible defaults + if not ndef.inventory_image then ndef.inventory_image = ndef.tiles[1] end + if not ndef.wield_image then ndef.wield_image = ndef.tiles[1] end + + print("registering sloped rail "..itemstring.." with definition: "..dump(ndef)) + + -- Make registrations + minetest.register_node(itemstring, ndef) + if craft then minetest.register_craft(craft) end +end +mod.register_rail_sloped = register_rail_sloped + -- Setup shared text local railuse = S( "Place them on the ground to build your railway, the rails will automatically connect to each other and will".. diff --git a/mods/ENTITIES/mcl_minecarts/rails/standard.lua b/mods/ENTITIES/mcl_minecarts/rails/standard.lua index 5e3378d66..e5aa00778 100644 --- a/mods/ENTITIES/mcl_minecarts/rails/standard.lua +++ b/mods/ENTITIES/mcl_minecarts/rails/standard.lua @@ -94,7 +94,7 @@ mod.update_rail_connections = update_rail_connections -- Now get the translator after we have finished using S for other things local S = minetest.get_translator(modname) local BASE_DEF = { - description = S("Rail"), + description = S("New Rail"), -- Temporary name to make debugging easier _tt_help = S("Track for minecarts"), _doc_items_longdesc = S("Rails can be used to build transport tracks for minecarts. Normal rails slightly slow down minecarts due to friction."), _doc_items_usagehelp = mod.text.railuse, @@ -161,6 +161,10 @@ local function register_curves_rail(base_name, tiles, def) } } })) + mod.register_rail_sloped(base_name.."_sloped", table_merge(table.copy(base_def),{ + description = S("Sloped Rail"), -- Temporary name to make debugging easier + tiles = { tiles[1] }, + })) -- Cross variant --[[