Fix crash when using nametag
[MineClone/MineClone2.git] / mods / ENTITIES / mcl_minecarts / rails.lua
blob05e0855c13d32c21a29275a2ec74f6b7129fe364
1 -- Template rail function
2 local register_rail = function(itemstring, tiles, def_extras, creative)
3 local 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}
4 if creative == false then
5 groups.not_in_creative_inventory = 1
6 end
7 local ndef = {
8 drawtype = "raillike",
9 tiles = tiles,
10 is_ground_content = false,
11 inventory_image = tiles[1],
12 wield_image = tiles[1],
13 paramtype = "light",
14 walkable = false,
15 selection_box = {
16 type = "fixed",
17 fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
19 stack_max = 64,
20 groups = groups,
21 sounds = mcl_sounds.node_sound_metal_defaults(),
22 _mcl_blast_resistance = 3.5,
23 _mcl_hardness = 0.7,
25 if def_extras then
26 for k,v in pairs(def_extras) do
27 ndef[k] = v
28 end
29 end
30 minetest.register_node(itemstring, ndef)
31 end
33 -- Redstone rules
34 local rail_rules_long =
35 {{x=-1, y= 0, z= 0, spread=true},
36 {x= 1, y= 0, z= 0, spread=true},
37 {x= 0, y=-1, z= 0, spread=true},
38 {x= 0, y= 1, z= 0, spread=true},
39 {x= 0, y= 0, z=-1, spread=true},
40 {x= 0, y= 0, z= 1, spread=true},
42 {x= 1, y= 1, z= 0},
43 {x= 1, y=-1, z= 0},
44 {x=-1, y= 1, z= 0},
45 {x=-1, y=-1, z= 0},
46 {x= 0, y= 1, z= 1},
47 {x= 0, y=-1, z= 1},
48 {x= 0, y= 1, z=-1},
49 {x= 0, y=-1, z=-1}}
51 local rail_rules_short = mesecon.rules.pplate
53 local railuse = "Place them on the ground to build your railway, the rails will automatically connect to each other and will turn into curves, T-junctions, crossings and slopes as needed."
55 -- Normal rail
56 register_rail("mcl_minecarts:rail",
57 {"default_rail.png", "default_rail_curved.png", "default_rail_t_junction.png", "default_rail_crossing.png"},
59 description = "Rail",
60 _doc_items_longdesc = "Rails can be used to build transport tracks for minecarts. Normal rails slightly slow down minecarts due to friction.",
61 _doc_items_usagehelp = railuse,
65 -- Powered rail (off = brake mode)
66 register_rail("mcl_minecarts:golden_rail",
67 {"carts_rail_pwr.png", "carts_rail_curved_pwr.png", "carts_rail_t_junction_pwr.png", "carts_rail_crossing_pwr.png"},
69 description = "Powered Rail",
70 _doc_items_longdesc = "Rails can be used to build transport tracks for minecarts. Powered rails are able to accelerate and brake minecarts.",
71 _doc_items_usagehelp = railuse .. "\n" .. "Without redstone power, the rail will brake minecarts. To make this rail accelerate minecarts, power it with redstone power.",
72 _rail_acceleration = -3,
73 mesecons = {
74 conductor = {
75 state = mesecon.state.off,
76 offstate = "mcl_minecarts:golden_rail",
77 onstate = "mcl_minecarts:golden_rail_on",
78 rules = rail_rules_long,
84 -- Powered rail (on = acceleration mode)
85 register_rail("mcl_minecarts:golden_rail_on",
86 {"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"},
88 _doc_items_create_entry = false,
89 _rail_acceleration = 4,
90 mesecons = {
91 conductor = {
92 state = mesecon.state.on,
93 offstate = "mcl_minecarts:golden_rail",
94 onstate = "mcl_minecarts:golden_rail_on",
95 rules = rail_rules_long,
98 drop = "mcl_minecarts:golden_rail",
100 false
103 -- Activator rail (off)
104 register_rail("mcl_minecarts:activator_rail",
105 {"mcl_minecarts_rail_activator.png", "mcl_minecarts_rail_activator_curved.png", "mcl_minecarts_rail_activator_t_junction.png", "mcl_minecarts_rail_activator_crossing.png"},
107 description = "Activator Rail",
108 _doc_items_longdesc = "Rails can be used to build transport tracks for minecarts. Activator rails are used to activate special minecarts.",
109 _doc_items_usagehelp = railuse .. "\n" .. "To make this rail activate minecarts, power it with redstone power and send a minecart over this piece of rail.",
110 mesecons = {
111 conductor = {
112 state = mesecon.state.off,
113 offstate = "mcl_minecarts:activator_rail",
114 onstate = "mcl_minecarts:activator_rail_on",
115 rules = rail_rules_long,
119 -- Hidden from creative because no cart is using this rail so far.
120 -- TODO: Remove this when the activator rail has become useful.
121 false
124 -- Activator rail (on)
125 register_rail("mcl_minecarts:activator_rail_on",
126 {"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_crossing_powered.png"},
128 _doc_items_create_entry = false,
129 mesecons = {
130 conductor = {
131 state = mesecon.state.on,
132 offstate = "mcl_minecarts:activator_rail",
133 onstate = "mcl_minecarts:activator_rail_on",
134 rules = rail_rules_long,
137 drop = "mcl_minecarts:activator_rail",
139 false
142 -- Detector rail (off)
143 register_rail("mcl_minecarts:detector_rail",
144 {"mcl_minecarts_rail_detector.png", "mcl_minecarts_rail_detector_curved.png", "mcl_minecarts_rail_detector_t_junction.png", "mcl_minecarts_rail_detector_crossing.png"},
146 description = "Detector Rail",
147 _doc_items_longdesc = "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.",
148 _doc_items_usagehelp = railuse .. "\n" .. "To detect a minecart and provide redstone power, connect it to redstone trails or redstone mechanisms and send any minecart over the rail.",
149 mesecons = {
150 receptor = {
151 state = mesecon.state.off,
152 rules = rail_rules_short,
158 -- Detector rail (on)
159 register_rail("mcl_minecarts:detector_rail_on",
160 {"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_crossing_powered.png"},
162 _doc_items_create_entry = false,
163 mesecons = {
164 receptor = {
165 state = mesecon.state.on,
166 rules = rail_rules_short,
169 drop = "mcl_minecarts:detector_rail",
171 false
175 -- Crafting
176 minetest.register_craft({
177 output = 'mcl_minecarts:rail 16',
178 recipe = {
179 {'mcl_core:iron_ingot', '', 'mcl_core:iron_ingot'},
180 {'mcl_core:iron_ingot', 'mcl_core:stick', 'mcl_core:iron_ingot'},
181 {'mcl_core:iron_ingot', '', 'mcl_core:iron_ingot'},
185 minetest.register_craft({
186 output = "mcl_minecarts:golden_rail 6",
187 recipe = {
188 {"mcl_core:gold_ingot", "", "mcl_core:gold_ingot"},
189 {"mcl_core:gold_ingot", "mcl_core:stick", "mcl_core:gold_ingot"},
190 {"mcl_core:gold_ingot", "mesecons:redstone", "mcl_core:gold_ingot"},
194 -- Activator rail crafting is disabled until it becomes useful.
195 -- TODO: Enable crafting as needed.
196 if false then
197 minetest.register_craft({
198 output = "mcl_minecarts:activator_rail 6",
199 recipe = {
200 {"mcl_core:iron_ingot", "mcl_core:stick", "mcl_core:iron_ingot"},
201 {"mcl_core:iron_ingot", "mesecons_torch:mesecon_torch_on", "mcl_core:iron_ingot"},
202 {"mcl_core:iron_ingot", "mcl_core:stick", "mcl_core:iron_ingot"},
207 minetest.register_craft({
208 output = "mcl_minecarts:detector_rail 6",
209 recipe = {
210 {"mcl_core:iron_ingot", "", "mcl_core:iron_ingot"},
211 {"mcl_core:iron_ingot", "mesecons_pressureplates:pressure_plate_stone_off", "mcl_core:iron_ingot"},
212 {"mcl_core:iron_ingot", "mesecons:redstone", "mcl_core:iron_ingot"},
217 -- Aliases
218 if minetest.get_modpath("doc") then
219 doc.add_entry_alias("nodes", "mcl_minecarts:golden_rail", "nodes", "mcl_minecarts:golden_rail_on")