railcarts/items.lua
Ciaran Gultnieks 80bbb57df2 Initial commit
2014-03-26 19:10:30 +00:00

155 lines
4.8 KiB
Lua

minetest.register_craft({
output = "railcarts:cart",
recipe = {
{"", "", ""},
{"default:steel_ingot", "", "default:steel_ingot"},
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
},
})
minetest.register_craft({
output = "railcarts:cargo_cart",
recipe = {
{"", "", ""},
{"default:steel_ingot", "default:chest", "default:steel_ingot"},
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
},
})
-- TODO : get rid of these when conversion is no longer needed
minetest.register_alias("railcarts:powerrail", "railcarts:controlrail")
minetest.register_alias("railcarts:powerrail_off", "railcarts:controlrail_off")
minetest.register_alias("railcarts:brakerail", "railcarts:controlrail")
minetest.register_alias("railcarts:brakerail_off", "railcarts:controlrail_off")
minetest.register_alias("railcarts:transport_cart", "railcarts:cargo_cart")
minetest.register_alias("railcarts:freight_cart", "railcarts:cargo_cart")
minetest.register_craftitem("railcarts:cart", {
description = "Cart",
image = minetest.inventorycube("railcarts_inv_cart_top.png",
"railcarts_inv_cart_side.png",
"railcarts_inv_cart_side.png"),
on_place = function(item, placer, pointed_thing)
if pointed_thing.type == "node" then
local pos = pointed_thing.above
pos.y = pos.y - 1
local railtype = get_railstatus(pos).railtype
if railtype ~= "inv" then
minetest.env:add_entity(pos,"railcarts:cart_ent")
if new_object ~= nil then
if railtype == "x" then
new_object:setyaw(0)
elseif railtype == "z" then
new_object:setyaw(0 + math.pi/2)
end
end
item:take_item()
end
end
return item
end
})
minetest.register_craftitem("railcarts:cargo_cart", {
description = "Cargo Cart",
image = minetest.inventorycube("railcarts_inv_transportcart_top.png",
"railcarts_inv_cart_side.png",
"railcarts_inv_cart_side.png"),
on_place = function(item, placer, pointed_thing)
if pointed_thing.type == "node" then
local pos = pointed_thing.above
pos.y = pos.y - 1
local railtype = get_railstatus(pos).railtype
if railtype ~= "inv" then
minetest.env:add_entity(pos,"railcarts:cargo_cart_ent")
if new_object ~= nil then
if railtype == "x" then
new_object:setyaw(0)
elseif railtype == "z" then
new_object:setyaw(0 + math.pi/2)
end
end
item:take_item()
end
end
return item
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)
debug.v2("Rails switched at "..postostr(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)
debug.v2("Rails switched back at "..postostr(pos))
end
}
}
})