1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
local modpath = minetest.get_modpath(minetest.get_current_modname())
dofile(modpath.."/railtrack.lua")
railtrack:register_rail(":default:rail", {
description = "Rail",
tiles = {"default_rail.png", "default_rail_curved.png",
"default_rail_t_junction.png", "default_rail_crossing.png"},
railtype = "rail",
})
railtrack:register_rail("railtrack:superrail", {
description = "Superconducting Rail",
tiles = {"carts_rail_sup.png", "carts_rail_curved_sup.png",
"carts_rail_t_junction_sup.png", "carts_rail_crossing_sup.png"},
railtype = "superrail",
acceleration = 0,
})
railtrack:register_rail("railtrack:powerrail", {
description = "Powered Rail",
tiles = {"carts_rail_pwr.png", "carts_rail_curved_pwr.png",
"carts_rail_t_junction_pwr.png", "carts_rail_crossing_pwr.png"},
railtype = "powerrail",
acceleration = 4,
mesecons = {
effector = {
action_on = function(pos, node)
railtrack:set_acceleration(pos, 4)
end,
action_off = function(pos, node)
railtrack:set_acceleration(pos, RAILTRACK_FRICTION_FLAT)
end,
},
},
})
railtrack:register_rail("railtrack:brakerail", {
description = "Braking Rail",
tiles = {"carts_rail_brk.png", "carts_rail_curved_brk.png",
"carts_rail_t_junction_brk.png", "carts_rail_crossing_brk.png"},
railtype = "brakerail",
acceleration = -4,
mesecons = {
effector = {
action_on = function(pos, node)
railtrack:set_acceleration(pos, -4)
end,
action_off = function(pos, node)
railtrack:set_acceleration(pos, RAILTRACK_FRICTION_FLAT)
end,
},
},
})
railtrack:register_rail("railtrack:switchrail", {
description = "Switching Rail",
tiles = {"carts_rail_swt.png", "carts_rail_curved_swt.png",
"carts_rail_t_junction_swt.png", "carts_rail_crossing_swt.png"},
railtype = "switchrail",
acceleration = 0,
mesecons = {
effector = {
action_on = function(pos, node)
local meta = minetest.get_meta(pos)
meta:set_string("rotations", "RFLB")
end,
action_off = function(pos, node)
local meta = minetest.get_meta(pos)
meta:set_string("rotations", nil)
end,
},
},
})
minetest.register_privilege("rails", "Player can dig and place rails.")
minetest.register_tool("railtrack:fixer", {
description = "Rail Fixer",
inventory_image = "railtrack_fixer.png",
wield_image = "railtrack_fixer.png",
on_use = function(itemstack, user, pointed_thing)
local pos = minetest.get_pointed_thing_position(pointed_thing, false)
local name = user:get_player_name()
if not pos or not name or pointed_thing.type ~= "node" then
return
end
if not railtrack:is_railnode(pos) then
minetest.chat_send_player(name, "Not a rail node!")
return
end
if not minetest.is_singleplayer() then
if not minetest.check_player_privs(name, {rails=true}) then
minetest.chat_send_player(name, "Requires rails privilege")
return
end
end
local node = minetest.get_node(pos)
if node then
minetest.remove_node(pos)
minetest.set_node(pos, node)
local def = minetest.registered_items[node.name] or {}
local itemstack = ItemStack(node.name)
if type(def.after_place_node) == "function" then
def.after_place_node(pos, user, itemstack)
end
end
end,
})
minetest.register_tool("railtrack:inspector", {
description = "Rail Inspector",
inventory_image = "railtrack_inspector.png",
wield_image = "railtrack_inspector.png",
on_use = function(itemstack, user, pointed_thing)
local name = user:get_player_name()
local pos = minetest.get_pointed_thing_position(pointed_thing, false)
if not name or not pos then
return
end
local node = minetest.get_node(pos) or {}
if not railtrack:is_railnode(pos) or not node.name then
minetest.chat_send_player(name, "Not a rail node!")
return
end
local ref = minetest.registered_items[node.name] or {}
local meta = minetest.get_meta(pos)
local form = ""
local size = 2.5
form = form.."label[0.5,0.5;POS: "..minetest.pos_to_string(pos).."]"
local railtype = ref.railtype or "NIL"
form = form.."label[0.5,1.0;RAILTYPE: "..railtype.."]"
local contype = meta:get_string("contype") or "NIL"
form = form.."label[0.5,1.5;CONTYPE: "..contype.."]"
local accel = meta:get_string("acceleration") or "NIL"
form = form.."label[0.5,2.0;ACCEL: "..accel.."]"
local s_junc = meta:get_string("junctions")
if s_junc then
local junctions = minetest.deserialize(s_junc)
if junctions then
form = form.."label[0.5,2.5;JUNCTIONS:]"
for i, p in ipairs(junctions) do
size = size + 0.5
form = form.."label[0.5,"..size..";#"..i.." "
..minetest.pos_to_string(p).."]"
end
end
end
local s_cons = meta:get_string("connections")
if s_cons then
local cons = minetest.deserialize(s_cons)
if cons then
size = size + 0.5
form = form.."label[0.5,"..size..";CONNECTIONS:]"
for i, p in pairs(cons) do
size = size + 0.5
form = form.."label[0.5,"..size..";#"..i.." "
..minetest.pos_to_string(p).."]"
end
end
end
local s_rots = meta:get_string("rotations")
if s_rots then
size = size + 0.5
form = form.."label[0.5,"..size..";ROTATIONS: "..s_rots.."]"
end
form = form.."button_exit[3.0,"..(size + 1)..";2,0.5;;Ok]"
form = "size[8,"..(size + 2).."]"..form
minetest.show_formspec(name, "info", form)
end,
})
minetest.register_craft({
output = "railtrack:powerrail 2",
recipe = {
{"default:rail", "default:mese_crystal_fragment", "default:rail"},
}
})
minetest.register_craft({
output = "railtrack:brakerail 2",
recipe = {
{"default:rail", "default:coal_lump", "default:rail"},
}
})
minetest.register_craft({
output = "railtrack:switchrail 2",
recipe = {
{"default:rail", "default:mese", "default:rail"},
}
})
minetest.register_craft({
output = "railtrack:superrail 2",
recipe = {
{"default:rail", "default:diamond", "default:rail"},
}
})
|