mirror of
https://cheapiesystems.com/git/mesecons_carts
synced 2024-11-19 22:03:52 +01:00
363 lines
11 KiB
Lua
363 lines
11 KiB
Lua
local mesecons_rules = {
|
|
{x = 1,y = 0,z = 0,},
|
|
{x = -1,y = 0,z = 0,},
|
|
{x = 0,y = 0,z = 1,},
|
|
{x = 0,y = 0,z = -1,},
|
|
{x = 1,y = -1,z = 0,},
|
|
{x = -1,y = -1,z = 0,},
|
|
{x = 0,y = -1,z = 1,},
|
|
{x = 0,y = -1,z = -1,},
|
|
{x = 0,y = -1,z = 0,},
|
|
}
|
|
|
|
carts:register_rail("mesecons_carts:power_rail_off", {
|
|
description = "Mesecons-Controlled Powered Rail",
|
|
tiles = {
|
|
"mesecons_carts_pwr_off_straight.png",
|
|
"mesecons_carts_pwr_off_curve.png",
|
|
"mesecons_carts_pwr_off_tjunction.png",
|
|
"mesecons_carts_pwr_off_crossing.png",
|
|
},
|
|
groups = carts:get_rail_groups(),
|
|
mesecons = {
|
|
effector = {
|
|
rules = mesecons_rules,
|
|
action_on = function(pos,node)
|
|
minetest.swap_node(pos,{name = "mesecons_carts:power_rail_on"})
|
|
end,
|
|
},
|
|
},
|
|
}, {})
|
|
|
|
carts:register_rail("mesecons_carts:power_rail_on", {
|
|
description = "Mesecons-Controlled Powered Rail (on state - you hacker you!)",
|
|
tiles = {
|
|
"mesecons_carts_pwr_on_straight.png",
|
|
"mesecons_carts_pwr_on_curve.png",
|
|
"mesecons_carts_pwr_on_tjunction.png",
|
|
"mesecons_carts_pwr_on_crossing.png",
|
|
},
|
|
drop = "mesecons_carts:power_rail_off",
|
|
groups = carts:get_rail_groups({not_in_creative_inventory = 1,}),
|
|
mesecons = {
|
|
effector = {
|
|
rules = mesecons_rules,
|
|
action_off = function(pos,node)
|
|
minetest.swap_node(pos,{name = "mesecons_carts:power_rail_off"})
|
|
end,
|
|
},
|
|
},
|
|
}, {acceleration = 5,})
|
|
|
|
carts:register_rail("mesecons_carts:power_rail_strong_off", {
|
|
description = "Mesecons-Controlled Strong Powered Rail",
|
|
tiles = {
|
|
"mesecons_carts_pwr_strong_off_straight.png",
|
|
"mesecons_carts_pwr_strong_off_curve.png",
|
|
"mesecons_carts_pwr_strong_off_tjunction.png",
|
|
"mesecons_carts_pwr_strong_off_crossing.png",
|
|
},
|
|
groups = carts:get_rail_groups(),
|
|
mesecons = {
|
|
effector = {
|
|
rules = mesecons_rules,
|
|
action_on = function(pos,node)
|
|
minetest.swap_node(pos,{name = "mesecons_carts:power_rail_strong_on"})
|
|
end,
|
|
},
|
|
},
|
|
}, {})
|
|
|
|
carts:register_rail("mesecons_carts:power_rail_strong_on", {
|
|
description = "Mesecons-Controlled Strong Powered Rail (on state - you hacker you!)",
|
|
tiles = {
|
|
"mesecons_carts_pwr_strong_on_straight.png",
|
|
"mesecons_carts_pwr_strong_on_curve.png",
|
|
"mesecons_carts_pwr_strong_on_tjunction.png",
|
|
"mesecons_carts_pwr_strong_on_crossing.png",
|
|
},
|
|
drop = "mesecons_carts:power_rail_strong_off",
|
|
groups = carts:get_rail_groups({not_in_creative_inventory = 1,}),
|
|
mesecons = {
|
|
effector = {
|
|
rules = mesecons_rules,
|
|
action_off = function(pos,node)
|
|
minetest.swap_node(pos,{name = "mesecons_carts:power_rail_strong_off"})
|
|
end,
|
|
},
|
|
},
|
|
}, {acceleration = 10,})
|
|
|
|
carts:register_rail("mesecons_carts:brake_rail_off", {
|
|
description = "Mesecons-Controlled Brake Rail",
|
|
tiles = {
|
|
"mesecons_carts_brk_off_straight.png",
|
|
"mesecons_carts_brk_off_curve.png",
|
|
"mesecons_carts_brk_off_tjunction.png",
|
|
"mesecons_carts_brk_off_crossing.png",
|
|
},
|
|
groups = carts:get_rail_groups(),
|
|
mesecons = {
|
|
effector = {
|
|
rules = mesecons_rules,
|
|
action_on = function(pos,node)
|
|
minetest.swap_node(pos,{name = "mesecons_carts:brake_rail_on"})
|
|
end,
|
|
},
|
|
},
|
|
}, {})
|
|
|
|
carts:register_rail("mesecons_carts:brake_rail_on", {
|
|
description = "Mesecons-Controlled Brake Rail (on state - you hacker you!)",
|
|
tiles = {
|
|
"mesecons_carts_brk_on_straight.png",
|
|
"mesecons_carts_brk_on_curve.png",
|
|
"mesecons_carts_brk_on_tjunction.png",
|
|
"mesecons_carts_brk_on_crossing.png",
|
|
},
|
|
drop = "mesecons_carts:brake_rail_off",
|
|
groups = carts:get_rail_groups({not_in_creative_inventory = 1,}),
|
|
mesecons = {
|
|
effector = {
|
|
rules = mesecons_rules,
|
|
action_off = function(pos,node)
|
|
minetest.swap_node(pos,{name = "mesecons_carts:brake_rail_off"})
|
|
end,
|
|
},
|
|
},
|
|
}, {acceleration = -5,})
|
|
|
|
carts:register_rail("mesecons_carts:brake_rail_strong_off", {
|
|
description = "Mesecons-Controlled Strong Brake Rail",
|
|
tiles = {
|
|
"mesecons_carts_brk_strong_off_straight.png",
|
|
"mesecons_carts_brk_strong_off_curve.png",
|
|
"mesecons_carts_brk_strong_off_tjunction.png",
|
|
"mesecons_carts_brk_strong_off_crossing.png",
|
|
},
|
|
groups = carts:get_rail_groups(),
|
|
mesecons = {
|
|
effector = {
|
|
rules = mesecons_rules,
|
|
action_on = function(pos,node)
|
|
minetest.swap_node(pos,{name = "mesecons_carts:brake_rail_strong_on"})
|
|
end,
|
|
},
|
|
},
|
|
}, {})
|
|
|
|
carts:register_rail("mesecons_carts:brake_rail_strong_on", {
|
|
description = "Mesecons-Controlled Strong Brake Rail (on state - you hacker you!)",
|
|
tiles = {
|
|
"mesecons_carts_brk_strong_on_straight.png",
|
|
"mesecons_carts_brk_strong_on_curve.png",
|
|
"mesecons_carts_brk_strong_on_tjunction.png",
|
|
"mesecons_carts_brk_strong_on_crossing.png",
|
|
},
|
|
drop = "mesecons_carts:brake_rail_strong_off",
|
|
groups = carts:get_rail_groups({not_in_creative_inventory = 1,}),
|
|
mesecons = {
|
|
effector = {
|
|
rules = mesecons_rules,
|
|
action_off = function(pos,node)
|
|
minetest.swap_node(pos,{name = "mesecons_carts:brake_rail_strong_off"})
|
|
end,
|
|
},
|
|
},
|
|
}, {acceleration = -10,})
|
|
|
|
local function detector_onstep(cart)
|
|
local cartpos = cart.object:get_pos()
|
|
local trackpos = {}
|
|
trackpos.x = math.floor(cartpos.x + 0.5)
|
|
trackpos.y = math.floor(cartpos.y + 0.5)
|
|
trackpos.z = math.floor(cartpos.z + 0.5)
|
|
local track = minetest.get_node(trackpos)
|
|
if track.name ~= "mesecons_carts:detector_rail_off" then return end
|
|
minetest.set_node(trackpos,{name = "mesecons_carts:detector_rail_on",})
|
|
mesecon.receptor_on(trackpos,mesecons_rules)
|
|
minetest.after(0.25,function(pos)
|
|
local node = minetest.get_node(pos)
|
|
if node.name == "mesecons_carts:detector_rail_on" then
|
|
minetest.set_node(pos,{name = "mesecons_carts:detector_rail_off",})
|
|
mesecon.receptor_off(pos,mesecons_rules)
|
|
end
|
|
end,trackpos)
|
|
end
|
|
|
|
carts:register_rail("mesecons_carts:detector_rail_off", {
|
|
description = "Mesecons Detector Rail",
|
|
tiles = {
|
|
"mesecons_carts_det_off_straight.png",
|
|
"mesecons_carts_det_off_curve.png",
|
|
"mesecons_carts_det_off_tjunction.png",
|
|
"mesecons_carts_det_off_crossing.png",
|
|
},
|
|
groups = carts:get_rail_groups(),
|
|
mesecons = {
|
|
receptor = {
|
|
rules = mesecons_rules,
|
|
state = mesecon.state.off,
|
|
},
|
|
},
|
|
}, {on_step = detector_onstep,})
|
|
|
|
carts:register_rail("mesecons_carts:detector_rail_on", {
|
|
description = "Mesecons Detector Rail (on state - you hacker you!)",
|
|
tiles = {
|
|
"mesecons_carts_det_on_straight.png",
|
|
"mesecons_carts_det_on_curve.png",
|
|
"mesecons_carts_det_on_tjunction.png",
|
|
"mesecons_carts_det_on_crossing.png",
|
|
},
|
|
drop = "mesecons_carts:detector_rail_off",
|
|
groups = carts:get_rail_groups({not_in_creative_inventory = 1,}),
|
|
mesecons = {
|
|
receptor = {
|
|
rules = mesecons_rules,
|
|
state = mesecon.state.on,
|
|
},
|
|
},
|
|
}, {})
|
|
|
|
minetest.register_lbm({
|
|
name = "mesecons_carts:detector_turnoff",
|
|
label = "Turn off detector rails",
|
|
nodenames = {"mesecons_carts:detector_rail_on",},
|
|
run_at_every_load = true,
|
|
action = function(pos)
|
|
minetest.set_node(pos,{name = "mesecons_carts:detector_rail_off",})
|
|
mesecon.receptor_off(pos,mesecons_rules)
|
|
end,
|
|
})
|
|
|
|
local function grab_cart(cart)
|
|
local cartpos = cart.object:get_pos()
|
|
local trackpos = {}
|
|
trackpos.x = math.floor(cartpos.x + 0.5)
|
|
trackpos.y = math.floor(cartpos.y + 0.5)
|
|
trackpos.z = math.floor(cartpos.z + 0.5)
|
|
local track = minetest.get_node(trackpos)
|
|
if track.name ~= "mesecons_carts:startstop_rail_off" then return end
|
|
local velocity = cart.object:get_velocity()
|
|
if velocity.x == 0 and velocity.y == 0 and velocity.z == 0 then return end
|
|
local meta = minetest.get_meta(trackpos)
|
|
meta:set_string("velocity",minetest.serialize(velocity))
|
|
cartpos.x = math.floor(cartpos.x + 0.5)
|
|
cartpos.z = math.floor(cartpos.z + 0.5)
|
|
cart.object:set_pos(cartpos)
|
|
meta:set_string("pos",minetest.serialize(cartpos))
|
|
cart.object:set_velocity(vector.new(0,0,0))
|
|
end
|
|
|
|
local function restart_cart(pos)
|
|
local meta = minetest.get_meta(pos)
|
|
local velocity_serial = meta:get_string("velocity")
|
|
local cartpos_serial = meta:get_string("pos")
|
|
if not (velocity_serial and cartpos_serial) then return end
|
|
local velocity = minetest.deserialize(velocity_serial)
|
|
local cartpos = minetest.deserialize(cartpos_serial)
|
|
if not (type(velocity) == "table" and type(cartpos) == "table") then return end
|
|
local possible_carts = minetest.get_objects_inside_radius(cartpos,1)
|
|
for _,object in pairs(possible_carts) do
|
|
local cart = object:get_luaentity()
|
|
if cart and cart.name == "carts:cart" then
|
|
cart.object:set_velocity(velocity)
|
|
end
|
|
end
|
|
end
|
|
|
|
carts:register_rail("mesecons_carts:startstop_rail_off", {
|
|
description = "Mesecons-Controlled Start-Stop Rail",
|
|
tiles = {
|
|
"mesecons_carts_startstop_off_straight.png",
|
|
"mesecons_carts_startstop_off_curve.png",
|
|
"mesecons_carts_startstop_off_tjunction.png",
|
|
"mesecons_carts_startstop_off_crossing.png",
|
|
},
|
|
groups = carts:get_rail_groups(),
|
|
mesecons = {
|
|
effector = {
|
|
rules = mesecons_rules,
|
|
action_on = function(pos,node)
|
|
minetest.swap_node(pos,{name = "mesecons_carts:startstop_rail_on"})
|
|
restart_cart(pos)
|
|
end,
|
|
},
|
|
},
|
|
}, {on_step = grab_cart,})
|
|
|
|
carts:register_rail("mesecons_carts:startstop_rail_on", {
|
|
description = "Mesecons-Controlled Start-Stop Rail (on state - you hacker you!)",
|
|
tiles = {
|
|
"mesecons_carts_startstop_on_straight.png",
|
|
"mesecons_carts_startstop_on_curve.png",
|
|
"mesecons_carts_startstop_on_tjunction.png",
|
|
"mesecons_carts_startstop_on_crossing.png",
|
|
},
|
|
drop = "mesecons_carts:startstop_rail_off",
|
|
groups = carts:get_rail_groups({not_in_creative_inventory = 1,}),
|
|
mesecons = {
|
|
effector = {
|
|
rules = mesecons_rules,
|
|
action_off = function(pos,node)
|
|
minetest.swap_node(pos,{name = "mesecons_carts:startstop_rail_off"})
|
|
end,
|
|
},
|
|
},
|
|
}, {})
|
|
|
|
minetest.register_craft({
|
|
output = "mesecons_carts:power_rail_off 3",
|
|
recipe = {
|
|
{"carts:rail","","",},
|
|
{"carts:rail","basic_materials:motor","mesecons:wire_00000000_off",},
|
|
{"carts:rail","","",},
|
|
},
|
|
})
|
|
|
|
minetest.register_craft({
|
|
output = "mesecons_carts:power_rail_strong_off 3",
|
|
recipe = {
|
|
{"carts:rail","basic_materials:motor","",},
|
|
{"carts:rail","","mesecons:wire_00000000_off",},
|
|
{"carts:rail","basic_materials:motor","",},
|
|
},
|
|
})
|
|
|
|
minetest.register_craft({
|
|
output = "mesecons_carts:brake_rail_off 3",
|
|
recipe = {
|
|
{"carts:rail","","",},
|
|
{"carts:rail","default:sand","mesecons:wire_00000000_off",},
|
|
{"carts:rail","","",},
|
|
},
|
|
})
|
|
|
|
minetest.register_craft({
|
|
output = "mesecons_carts:brake_rail_strong_off 3",
|
|
recipe = {
|
|
{"carts:rail","default:sand","",},
|
|
{"carts:rail","","mesecons:wire_00000000_off",},
|
|
{"carts:rail","default:sand","",},
|
|
},
|
|
})
|
|
|
|
minetest.register_craft({
|
|
output = "mesecons_carts:detector_rail_off 3",
|
|
recipe = {
|
|
{"carts:rail","","",},
|
|
{"carts:rail","mesecons_detector:object_detector_off","mesecons:wire_00000000_off",},
|
|
{"carts:rail","","",},
|
|
},
|
|
})
|
|
|
|
minetest.register_craft({
|
|
output = "mesecons_carts:startstop_rail_off 3",
|
|
recipe = {
|
|
{"carts:rail","basic_materials:motor","",},
|
|
{"carts:rail","","mesecons:wire_00000000_off",},
|
|
{"carts:rail","default:sand","",},
|
|
},
|
|
})
|