-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.lua
72 lines (63 loc) · 1.84 KB
/
node.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
local S = core.get_translator(equip_exam.name)
local common_name = S("Equipment Examiner")
local function update_formspec(pos)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
local inv_list = inv:get_list("input")
if not inv_list then
inv:set_size("input", 1)
inv_list = inv:get_list("input")
end
meta:set_string("formspec", equip_exam:get_formspec(inv_list[1],
inv:is_empty("input"), meta))
end
local node_def = {
description = common_name,
short_description = common_name,
drawtype = "normal",
tiles = {
"equip_exam_examiner.png",
"equip_exam_examiner.png",
"equip_exam_examiner.png",
"equip_exam_examiner.png",
"equip_exam_examiner.png",
"equip_exam_examiner_front.png",
"equip_exam_examiner.png",
},
groups = {oddly_breakable_by_hand=1,},
is_ground_content = false,
stack_max = 1,
paramtype2 = "facedir",
on_construct = function(pos)
local meta = core.get_meta(pos)
meta:set_string("infotext", common_name)
update_formspec(pos)
end,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
update_formspec(pos)
end,
can_dig = function(pos, player)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
return inv:is_empty("input")
end,
-- FIXME: both are called when item is replaced with another
on_metadata_inventory_put = function(pos, listname, index, stack, player)
update_formspec(pos)
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
update_formspec(pos)
end,
on_receive_fields = function(pos, formname, fields, sender)
if fields.techname then
local nmeta = core.get_meta(pos)
if fields.techname == "true" then
nmeta:set_string("show_technical", "true")
else
nmeta:set_string("show_technical", nil)
end
update_formspec(pos)
end
end
}
core.register_node("equip_exam:examiner", node_def)