Basic powered rails implementation

This commit is contained in:
Wuzzy 2017-08-28 16:59:10 +02:00
parent 213edbe85c
commit 36319afbbe
16 changed files with 78 additions and 37 deletions

View file

@ -33,11 +33,26 @@ minetest.register_craft({
}
})
-- Rail to speed up
minetest.register_node("mcl_minecarts:golden_rail", {
-- Function that get the input/output rules of the powered rails
local get_input_rules = function()
return {
{x = -1, y = 0, z = 0},
{x = 1, y = 0, z = 0},
{x = 0, y = 0, z = -1},
{x = 0, y = 0, z = 1},
}
end
local get_output_rules = function()
return {}
end
-- Powered rail
local powered_rail_template = {
description = "Powered Rail",
_doc_items_longdesc = "Rails can be used to build transport tracks for minecarts. Powered rails will accelerate moving minecarts, up to a maximum speed.",
_doc_items_usagehelp = railuse,
_doc_items_longdesc = "Rails can be used to build transport tracks for minecarts. Powered rails are able to accelerate and brake minecarts.",
_doc_items_usagehelp = railuse .. "\n" .. "Without redstone power, the rail will brake minecarts. To make this rail accelerate minecarts, power it with redstone power.",
drawtype = "raillike",
tiles = {"carts_rail_pwr.png", "carts_rail_curved_pwr.png", "carts_rail_t_junction_pwr.png", "carts_rail_crossing_pwr.png"},
inventory_image = "carts_rail_pwr.png",
@ -47,31 +62,61 @@ minetest.register_node("mcl_minecarts:golden_rail", {
walkable = false,
selection_box = {
type = "fixed",
-- but how to specify the dimensions for curved and sideways rails?
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {handy=1,pickaxey=1, attached_node = 1, rail = 1, connect_to_raillike = 1, dig_by_water = 1,destroy_by_lava_flow=1, transport = 1},
after_place_node = function(pos, placer, itemstack)
if not mesecon then
minetest.get_meta(pos):set_string("cart_acceleration", "0.5")
end
end,
sounds = mcl_sounds.node_sound_metal_defaults(),
mesecons = {
effector = {
action_on = function(pos, node)
mcl_minecarts:boost_rail(pos, 0.5)
end,
action_off = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0")
minetest.swap_node(pos, {name = "mcl_minecarts:golden_rail_on", param2 = node.param2 })
mesecon:receptor_on(pos, get_input_rules())
end,
},
receptor = {
state = mesecon.state.off,
rules = get_output_rules,
},
},
_rail_acceleration = -3,
_mcl_blast_resistance = 3.5,
_mcl_hardness = 0.7,
})
}
minetest.register_node("mcl_minecarts:golden_rail", powered_rail_template)
-- Powered rail (activated by redstone)
local powered_rail_on = table.copy(powered_rail_template)
powered_rail_on.description = nil
powered_rail_on._doc_items_create_entry = false
powered_rail_on._doc_items_longdesc = nil
powered_rail_on._doc_items_usagehelp = nil
powered_rail_on.tiles = {"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_crossing_powered.png"}
powered_rail_on.inventory_image = "mcl_minecarts_rail_golden_powered.png"
powered_rail_on.wield_image = "mcl_minecarts_rail_golden_powered.png"
powered_rail_on.groups.not_in_creative_inventory = 1
powered_rail_on.groups.transport = nil
powered_rail_on.mesecons = {
effector = {
action_off = function(pos, node)
minetest.swap_node(pos, {name = "mcl_minecarts:golden_rail", param2 = node.param2 })
mesecon:receptor_off(pos, get_input_rules())
end,
},
receptor = {
state = mesecon.state.on,
rules = get_output_rules,
}
}
powered_rail_on._rail_acceleration = 4
minetest.register_node("mcl_minecarts:golden_rail_on", powered_rail_on)
if minetest.get_modpath("doc") then
doc.add_entry_alias("nodes", "mcl_minecarts:golden_rail", "nodes", "mcl_minecarts:golden_rail_on")
end
minetest.register_craft({
output = "mcl_minecarts:golden_rail 6",