railcarts/defaultrail.lua
2014-03-28 08:54:02 +00:00

71 lines
2.1 KiB
Lua

local dbg
if moddebug then dbg=moddebug.dbg("railcarts") else dbg={v1=function() end,v2=function() end,v3=function() end} end
local railrules = {
{x = 0, y = -1, z = 0},
{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},
}
minetest.register_node(":default:rail", {
description = "Rail",
drawtype = "raillike",
tiles = {"default_rail.png", "default_rail_curved.png", "default_rail_t_junction.png", "default_rail_crossing.png"},
inventory_image = "default_rail.png",
wield_image = "default_rail.png",
paramtype = "light",
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {bendy=2,snappy=1,dig_immediate=2,attached_node=1,rail=1,connect_to_raillike=1},
mesecons = {
effector = {
rules = railrules,
action_on =
function(pos, node)
node.name = "railcarts:rail_switched"
minetest.swap_node(pos, node)
dbg.v2("Rails switched at "..minetest.pos_to_string(pos))
end
}
}
})
minetest.register_node("railcarts:rail_switched", {
description = "Rail",
drawtype = "raillike",
drop = 'default:rail 1',
tiles = {"default_rail.png", "default_rail_curved.png", "railcarts_rail_t_junction_switched.png", "default_rail_crossing.png"},
paramtype = "light",
is_ground_content = true,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {bendy=2,snappy=1,dig_immediate=2,attached_node=1,rail=1,connect_to_raillike=1},
mesecons = {
effector = {
rules = railrules,
action_off =
function(pos, node)
node.name = "default:rail"
minetest.swap_node(pos, node)
dbg.v2("Rails switched back at "..minetest.pos_to_string(pos))
end
}
}
})