Add in working curved variants of special rails

This commit is contained in:
teknomunk 2024-11-09 15:14:57 -06:00
parent bceb070849
commit d1c4b3ddc2
5 changed files with 112 additions and 66 deletions

View File

@ -202,6 +202,57 @@ function mod.register_rail(itemstring, ndef)
if craft then minetest.register_craft(craft) end
end
local function make_mesecons(base_name, suffix, base_mesecons)
if not base_mesecons then
if suffix == "_tee_off" or suffix == "_tee_on" then
base_mesecons = {}
else
return
end
end
local mesecons = table.copy(base_mesecons)
if suffix == "_tee_off" then
mesecons.effector = base_mesecons.effector and table.copy(base_mesecons.effector) or {}
local old_action_on = base_mesecons.effector and base_mesecons.effector.action_on
mesecons.effector.action_on = function(pos, node)
if old_action_on then old_action_on(pos, node) end
node.name = base_name.."_tee_on"
minetest.set_node(pos, node)
end
mesecons.effector.rules = mesecons.effector.rules or mesecon.rules.alldirs
elseif suffix == "_tee_on" then
mesecons.effector = base_mesecons.effector and table.copy(base_mesecons.effector) or {}
local old_action_off = base_mesecons.effector and base_mesecons.effector.action_off
mesecons.effector.action_off = function(pos, node)
if old_action_off then old_action_off(pos, node) end
node.name = base_name.."_tee_off"
minetest.set_node(pos, node)
end
mesecons.effector.rules = mesecons.effector.rules or mesecon.rules.alldirs
end
if mesecons.conductor then
mesecons.conductor = table.copy(base_mesecons.conductor)
if mesecons.conductor.onstate then
mesecons.conductor.onstate = base_mesecons.conductor.onstate..suffix
end
if base_mesecons.conductor.offstate then
mesecons.conductor.offstate = base_mesecons.conductor.offstate..suffix
end
end
minetest.log("mesecons for "..base_name..suffix.." is "..dump(mesecons))
return mesecons
end
function mod.register_straight_rail(base_name, tiles, def)
def = def or {}
local base_def = table.copy(BASE_DEF)
@ -226,6 +277,7 @@ function mod.register_straight_rail(base_name, tiles, def)
table_merge(base_def,{
_mcl_minecarts = {
railtype = "straight",
suffix = "",
},
})
@ -233,8 +285,9 @@ function mod.register_straight_rail(base_name, tiles, def)
mod.register_rail_sloped(base_name.."_sloped", table_merge(table.copy(sloped_def),{
_mcl_minecarts = {
get_next_dir = rail_dir_sloped,
suffix = "_sloped",
},
mesecons = def.mesecons_sloped,
mesecons = make_mesecons(base_name, "_sloped", def.mesecons),
tiles = { tiles[1] },
_mcl_minecarts = {
railtype = "sloped",
@ -263,6 +316,7 @@ function mod.register_curves_rail(base_name, tiles, def)
get_next_dir = rail_dir_straight,
railtype = "straight",
can_slope = true,
suffix = "",
},
}))
@ -280,24 +334,19 @@ function mod.register_curves_rail(base_name, tiles, def)
_mcl_minecarts = {
get_next_dir = rail_dir_curve,
railtype = "corner",
suffix = "_corner",
},
mesecons = make_mesecons(base_name, "_corner", def.mesecons),
}))
-- Tee variants
mod.register_rail(base_name.."_tee_off", table_merge(table.copy(base_def),{
tiles = { tiles[3] },
mesecons = {
effector = {
action_on = function(pos, node)
local new_node = {name = base_name.."_tee_on", param2 = node.param2}
minetest.swap_node(pos, new_node)
end,
rules = mesecon.rules.alldirs,
}
},
mesecons = make_mesecons(base_name, "_tee_off", def.mesecons),
_mcl_minecarts = {
get_next_dir = rail_dir_tee_off,
railtype = "tee",
suffix = "_tee_off",
},
}))
mod.register_rail(base_name.."_tee_on", table_merge(table.copy(base_def),{
@ -305,16 +354,9 @@ function mod.register_curves_rail(base_name, tiles, def)
_mcl_minecarts = {
get_next_dir = rail_dir_tee_on,
railtype = "tee",
suffix = "_tee_on",
},
mesecons = {
effector = {
action_off = function(pos, node)
local new_node = {name = base_name.."_tee_off", param2 = node.param2}
minetest.swap_node(pos, new_node)
end,
rules = mesecon.rules.alldirs,
}
}
mesecons = make_mesecons(base_name, "_tee_on", def.mesecons),
}))
-- Sloped variant
@ -323,7 +365,9 @@ function mod.register_curves_rail(base_name, tiles, def)
_mcl_minecarts = {
get_next_dir = rail_dir_sloped,
railtype = "tee",
suffix = "_sloped",
},
mesecons = make_mesecons(base_name, "_sloped", def.mesecons),
tiles = { tiles[1] },
}))
@ -333,7 +377,9 @@ function mod.register_curves_rail(base_name, tiles, def)
_mcl_minecarts = {
get_next_dir = rail_dir_cross,
railtype = "cross",
suffix = "_cross",
},
mesecons = make_mesecons(base_name, "_cross", def.mesecons),
}))
end

View File

@ -4,7 +4,13 @@ local mod = mcl_minecarts
local S = minetest.get_translator(modname)
-- Activator rail (off)
mod.register_straight_rail("mcl_minecarts:activator_rail_v2", {"mcl_minecarts_rail_activator.png"},{
mod.register_curves_rail("mcl_minecarts:activator_rail_v2", {
"mcl_minecarts_rail_activator.png",
"mcl_minecarts_rail_activator_curved.png",
"mcl_minecarts_rail_activator_t_junction.png",
"mcl_minecarts_rail_activator_t_junction.png",
"mcl_minecarts_rail_activator_crossing.png"
},{
description = S("Activator Rail"),
_tt_help = S("Track for minecarts").."\n"..S("Activates minecarts when powered"),
_doc_items_longdesc = S("Rails can be used to build transport tracks for minecarts. Activator rails are used to activate special minecarts."),
@ -17,14 +23,6 @@ mod.register_straight_rail("mcl_minecarts:activator_rail_v2", {"mcl_minecarts_ra
rules = mod.rail_rules_long,
},
},
mesecons_sloped = {
conductor = {
state = mesecon.state.off,
offstate = "mcl_minecarts:activator_rail_v2_sloped",
onstate = "mcl_minecarts:activator_rail_v2_on_sloped",
rules = mod.rail_rules_long,
},
},
craft = {
output = "mcl_minecarts:activator_rail_v2 6",
recipe = {
@ -46,7 +44,13 @@ local function activator_rail_action_on(pos, node)
end
end
end
mod.register_straight_rail("mcl_minecarts:activator_rail_v2_on", {"mcl_minecarts_rail_activator_powered.png"},{
mod.register_curves_rail("mcl_minecarts:activator_rail_v2_on", {
"mcl_minecarts_rail_activator_powered.png",
"mcl_minecarts_rail_activator_curved_powered.png",
"mcl_minecarts_rail_activator_t_junction_powered.png",
"mcl_minecarts_rail_activator_t_junction_powered.png",
"mcl_minecarts_rail_activator_crossing_powered.png"
},{
_doc_items_create_entry = false,
groups = {
not_in_creative_inventory = 1,
@ -62,20 +66,6 @@ mod.register_straight_rail("mcl_minecarts:activator_rail_v2_on", {"mcl_minecarts
-- Activate minecarts
action_on = activator_rail_action_on,
},
},
mesecons_sloped = {
conductor = {
state = mesecon.state.on,
offstate = "mcl_minecarts:activator_rail_v2_sloped",
onstate = "mcl_minecarts:activator_rail_v2_on_sloped",
rules = mod.rail_rules_long,
},
effector = {
-- Activate minecarts
action_on = activator_rail_action_on,
},
},
_mcl_minecarts_on_enter = function(pos, cart)
if cart.on_activate_by_rail then

View File

@ -6,7 +6,13 @@ local S = minetest.get_translator(modname)
local rail_rules_short = mesecon.rules.pplate
-- Detector rail (off)
mod.register_straight_rail("mcl_minecarts:detector_rail_v2",{"mcl_minecarts_rail_detector.png"},{
mod.register_curves_rail("mcl_minecarts:detector_rail_v2",{
"mcl_minecarts_rail_detector.png",
"mcl_minecarts_rail_detector_curved.png",
"mcl_minecarts_rail_detector_t_junction.png",
"mcl_minecarts_rail_detector_t_junction.png",
"mcl_minecarts_rail_detector_crossing.png"
},{
description = S("Detector Rail"),
_tt_help = S("Track for minecarts").."\n"..S("Emits redstone power when a minecart is detected"),
_doc_items_longdesc = S("Rails can be used to build transport tracks for minecarts. A detector rail is able to detect a minecart above it and powers redstone mechanisms."),
@ -19,7 +25,8 @@ mod.register_straight_rail("mcl_minecarts:detector_rail_v2",{"mcl_minecarts_rail
},
_mcl_minecarts_on_enter = function(pos, cart)
local node = minetest.get_node(pos)
node.name = "mcl_minecarts:detector_rail_v2_on"
local node_def = minetest.registered_nodes[node.name]
node.name = "mcl_minecarts:detector_rail_v2_on"..node_def._mcl_minecarts.suffix
minetest.set_node( pos, node )
mesecon.receptor_on(pos)
end,
@ -34,7 +41,13 @@ mod.register_straight_rail("mcl_minecarts:detector_rail_v2",{"mcl_minecarts_rail
})
-- Detector rail (on)
mod.register_straight_rail("mcl_minecarts:detector_rail_v2_on",{"mcl_minecarts_rail_detector_powered.png"},{
mod.register_curves_rail("mcl_minecarts:detector_rail_v2_on",{
"mcl_minecarts_rail_detector_powered.png",
"mcl_minecarts_rail_detector_curved_powered.png",
"mcl_minecarts_rail_detector_t_junction_powered.png",
"mcl_minecarts_rail_detector_t_junction_powered.png",
"mcl_minecarts_rail_detector_crossing_powered.png"
},{
groups = {
not_in_creative_inventory = 1,
},
@ -47,7 +60,8 @@ mod.register_straight_rail("mcl_minecarts:detector_rail_v2_on",{"mcl_minecarts_r
},
_mcl_minecarts_on_leave = function(pos, cart)
local node = minetest.get_node(pos)
node.name = "mcl_minecarts:detector_rail_v2"
local node_def = minetest.registered_nodes[node.name]
node.name = "mcl_minecarts:detector_rail_v2"..node_def._mcl_minecarts.suffix
minetest.set_node( pos, node )
mesecon.receptor_off(pos)
end,

View File

@ -5,7 +5,7 @@ local S = minetest.get_translator(modname)
-- Normal rail
mod.register_curves_rail("mcl_minecarts:rail_v2", {
"default_rail.png",
"default_rail.png",
"default_rail_curved.png",
"default_rail_t_junction.png",
"default_rail_t_junction_on.png",

View File

@ -4,7 +4,13 @@ local mod = mcl_minecarts
local S = minetest.get_translator(modname)
-- Powered rail (off = brake mode)
mod.register_straight_rail("mcl_minecarts:golden_rail_v2",{ "mcl_minecarts_rail_golden.png" },{
mod.register_curves_rail("mcl_minecarts:golden_rail_v2",{
"mcl_minecarts_rail_golden.png",
"mcl_minecarts_rail_golden_curved.png",
"mcl_minecarts_rail_golden_t_junction.png",
"mcl_minecarts_rail_golden_t_junction.png",
"mcl_minecarts_rail_golden_crossing.png"
},{
description = S("Powered Rail"),
_tt_help = S("Track for minecarts").."\n"..S("Speed up when powered, slow down when not powered"),
_doc_items_longdesc = S("Rails can be used to build transport tracks for minecarts. Powered rails are able to accelerate and brake minecarts."),
@ -21,14 +27,6 @@ mod.register_straight_rail("mcl_minecarts:golden_rail_v2",{ "mcl_minecarts_rail_
rules = mod.rail_rules_long,
},
},
mesecons_sloped = {
conductor = {
state = mesecon.state.off,
offstate = "mcl_minecarts:golden_rail_v2_sloepd",
onstate = "mcl_minecarts:golden_rail_v2_on_sloped",
rules = mod.rail_rules_long,
},
},
drop = "mcl_minecarts:golden_rail_v2",
craft = {
output = "mcl_minecarts:golden_rail_v2 6",
@ -41,7 +39,13 @@ mod.register_straight_rail("mcl_minecarts:golden_rail_v2",{ "mcl_minecarts_rail_
})
-- Powered rail (on = acceleration mode)
mod.register_straight_rail("mcl_minecarts:golden_rail_v2_on",{ "mcl_minecarts_rail_golden_powered.png" },{
mod.register_curves_rail("mcl_minecarts:golden_rail_v2_on",{
"mcl_minecarts_rail_golden_powered.png",
"mcl_minecarts_rail_golden_curved_powered.png",
"mcl_minecarts_rail_golden_t_junction_powered.png",
"mcl_minecarts_rail_golden_t_junction_powered.png",
"mcl_minecarts_rail_golden_crossing_powered.png",
},{
_doc_items_create_entry = false,
_rail_acceleration = function(pos, staticdata)
if staticdata.velocity ~= 0 then
@ -74,14 +78,6 @@ mod.register_straight_rail("mcl_minecarts:golden_rail_v2_on",{ "mcl_minecarts_ra
rules = mod.rail_rules_long,
},
},
mesecons_sloped = {
conductor = {
state = mesecon.state.on,
offstate = "mcl_minecarts:golden_rail_v2_sloped",
onstate = "mcl_minecarts:golden_rail_v2_on_sloped",
rules = mod.rail_rules_long,
},
},
drop = "mcl_minecarts:golden_rail_v2",
})