-
Notifications
You must be signed in to change notification settings - Fork 0
/
blueprints.lua
126 lines (87 loc) · 3.14 KB
/
blueprints.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
118
119
120
121
122
123
124
125
126
minetest.register_craftitem("bitumen:blueprint_paper", {
description = "Blueprint Paper",
stack_max = 99,
inventory_image = "default_paper.png^[colorize:blue:120",
groups = {flammable = 3},
})
minetest.register_craftitem("bitumen:blueprint_book", {
description = "Blueprint Paper",
stack_max = 99,
inventory_image = "default_book.png^[colorize:blue:120",
groups = {flammable = 3},
})
bitumen.registered_blueprints = {
-- ["bitumen:cement_mixer_blueprint"] = 1,
}
-- registers the blueprint item, adds it to the bookshelf, and registers the constructor craft recipe
bitumen.register_blueprint = function(def)
local name = def.name.."_blueprint"
local parent_def = minetest.registered_nodes[def.name]
if parent_def == nil then
print("Warning: parent node not registered yet. Place bitumen.register_blueprint call after node registration.")
return
end
minetest.register_craftitem(name, {
description = parent_def.description.." Blueprint",
stack_max = 1,
inventory_image = parent_def.inventory_image .. "^bitumen_blueprint.png",
groups = {flammable = 3},
})
if not def.no_constructor_craft then
-- the actual constructor must be registered elsewhere
minetest.register_craft({
output = def.name..'_constructor',
recipe = {
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
{'default:steel_ingot', name, 'default:steel_ingot'},
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
}
})
end
bitumen.registered_blueprints[name] = def
end
local blueprint_bookshelf_formspec =
"size[8,8;]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"list[context;blueprints;0,0.3;8,3;]" ..
"list[current_player;main;0,3.85;8,1;]" ..
"list[current_player;main;0,5.08;8,3;8]" ..
"listring[context;blueprints]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0,3.85)
minetest.register_node("bitumen:blueprint_bookshelf", {
description = "Blueprint Bookshelf",
tiles = {"default_junglewood.png", "default_junglewood.png", "default_junglewood.png",
"default_junglewood.png", "default_bookshelf.png^[colorize:blue:120", "default_junglewood.png"},
paramtype2 = "facedir",
is_ground_content = false,
groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
sounds = default.node_sound_wood_defaults(),
stack_max = 1,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", blueprint_bookshelf_formspec)
local inv = meta:get_inventory()
inv:set_size("blueprints", 8 * 3)
-- fill in the known blueprints
local list = {}
for name,def in pairs(bitumen.registered_blueprints) do
table.insert(list, name)
end
inv:set_list("blueprints", list)
end,
allow_metadata_inventory_put = function(pos, listname, index, stack)
return 0
end,
allow_metadata_inventory_move = function(pos, listname, index, stack)
return 0
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
-- print(" -- "..listname.. " " ..index.." "..dump(stack))
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory(meta)
inv:set_stack(listname, index, stack)
end,
})