-
Notifications
You must be signed in to change notification settings - Fork 14
/
train.lua
117 lines (91 loc) · 2.79 KB
/
train.lua
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
local last_set_by = {}
local update_formspec = function(meta)
local line = meta:get_string("line")
local station = meta:get_string("station")
local index = meta:get_string("index")
local color = meta:get_string("color") or ""
meta:set_string("infotext", "Train: Line=" .. line .. ", Station=" .. station)
meta:set_string("formspec", "size[8,4;]" ..
-- col 1
"field[0,1;4,1;line;Line;" .. line .. "]" ..
"button_exit[4,1;4,1;save;Save]" ..
-- col 2
"field[0,2.5;4,1;station;Station;" .. station .. "]" ..
"field[4,2.5;4,1;index;Index;" .. index .. "]" ..
-- col 3
"field[0,3.5;4,1;color;Color;" .. color .. "]" ..
""
)
end
minetest.register_node("mapserver:train", {
description = "Mapserver Train",
tiles = {
"mapserver_train.png"
},
groups = {cracky=3,oddly_breakable_by_hand=3,handy=1},
is_ground_content = false,
sounds = moditems.sound_glass(),
can_dig = mapserver.can_interact,
_mcl_blast_resistance = 1,
_mcl_hardness = 0.3,
after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
local last_index = 0
local last_line = ""
local last_color = ""
if minetest.is_player(placer) then
local name = placer:get_player_name()
if name ~= nil then
name = string.lower(name)
if last_set_by[name] ~= nil then
last_index = last_set_by[name].index + 5
last_line = last_set_by[name].line
last_color = last_set_by[name].color
else
last_set_by[name] = {}
end
last_set_by[name].index = last_index
last_set_by[name].line = last_line
last_set_by[name].color = last_color
end
end
meta:set_string("station", "")
meta:set_string("line", last_line)
meta:set_int("index", last_index)
meta:set_string("color", last_color)
update_formspec(meta)
return mapserver.after_place_node(pos, placer, itemstack, pointed_thing)
end,
on_receive_fields = function(pos, formname, fields, sender)
if not mapserver.can_interact(pos, sender) then
return
end
local meta = minetest.get_meta(pos)
local name = string.lower(sender:get_player_name())
if fields.save then
if last_set_by[name] == nil then
last_set_by[name] = {}
end
local index = tonumber(fields.index) or 0
meta:set_string("color", fields.color)
meta:set_string("line", fields.line)
meta:set_string("station", fields.station)
meta:set_int("index", index)
last_set_by[name].color = fields.color
last_set_by[name].line = fields.line
last_set_by[name].station = fields.station
last_set_by[name].index = index
end
update_formspec(meta)
end
})
if mapserver.enable_crafting then
minetest.register_craft({
output = 'mapserver:train',
recipe = {
{"", moditems.steel_ingot, ""},
{moditems.paper, moditems.goldblock, moditems.paper},
{"", moditems.glass, ""}
}
})
end