-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
233 lines (209 loc) · 5.97 KB
/
init.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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
-- vessels/init.lua
-- Minetest 0.4 mod: vessels
-- See README.txt for licensing and other information.
-- Load support for MT game translation.
local S = minetest.get_translator("vessels")
local vessels_shelf_formspec =
"size[8,7;]" ..
"list[context;vessels;0,0.3;8,2;]" ..
"list[current_player;main;0,2.85;8,1;]" ..
"list[current_player;main;0,4.08;8,3;8]" ..
"listring[context;vessels]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0, 2.85)
local function update_vessels_shelf(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local invlist = inv:get_list("vessels")
local formspec = vessels_shelf_formspec
-- Inventory slots overlay
local vx, vy = 0, 0.3
local n_items = 0
for i = 1, 16 do
if i == 9 then
vx = 0
vy = vy + 1
end
if not invlist or invlist[i]:is_empty() then
formspec = formspec ..
"image[" .. vx .. "," .. vy .. ";1,1;vessels_shelf_slot.png]"
else
local stack = invlist[i]
if not stack:is_empty() then
n_items = n_items + stack:get_count()
end
end
vx = vx + 1
end
meta:set_string("formspec", formspec)
if n_items == 0 then
meta:set_string("infotext", S("Empty Vessels Shelf"))
else
meta:set_string("infotext", S("Vessels Shelf (@1 items)", n_items))
end
end
local vessels_shelf_def = {
description = S("Vessels Shelf"),
tiles = {"default_wood.png", "default_wood.png", "default_wood.png",
"default_wood.png", "vessels_shelf.png", "vessels_shelf.png"},
paramtype2 = "facedir",
is_ground_content = false,
groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
update_vessels_shelf(pos)
local inv = meta:get_inventory()
inv:set_size("vessels", 8 * 2)
end,
can_dig = function(pos,player)
local inv = minetest.get_meta(pos):get_inventory()
return inv:is_empty("vessels")
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if minetest.get_item_group(stack:get_name(), "vessel") ~= 0 then
return stack:get_count()
end
return 0
end,
on_blast = function(pos)
local drops = {}
default.get_inventory_drops(pos, "vessels", drops)
drops[#drops + 1] = "vessels:shelf"
minetest.remove_node(pos)
return drops
end,
on_metadata_inventory_put = function(pos)
update_vessels_shelf(pos)
end,
on_metadata_inventory_take = function(pos)
update_vessels_shelf(pos)
end,
on_metadata_inventory_move = function(pos)
update_vessels_shelf(pos)
end,
}
default.set_inventory_action_loggers(vessels_shelf_def, "vessels shelf")
minetest.register_node("vessels:shelf", vessels_shelf_def)
minetest.register_craft({
output = "vessels:shelf",
recipe = {
{"group:wood", "group:wood", "group:wood"},
{"group:vessel", "group:vessel", "group:vessel"},
{"group:wood", "group:wood", "group:wood"},
}
})
minetest.register_node("vessels:glass_bottle", {
description = S("Empty Glass Bottle"),
drawtype = "plantlike",
tiles = {"vessels_glass_bottle.png"},
inventory_image = "vessels_glass_bottle.png",
wield_image = "vessels_glass_bottle.png",
paramtype = "light",
is_ground_content = false,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
},
groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
sounds = default.node_sound_glass_defaults(),
})
minetest.register_craft( {
output = "vessels:glass_bottle 10",
recipe = {
{"default:glass", "", "default:glass"},
{"default:glass", "", "default:glass"},
{"", "default:glass", ""}
}
})
minetest.register_node("vessels:drinking_glass", {
description = S("Empty Drinking Glass"),
drawtype = "plantlike",
tiles = {"vessels_drinking_glass.png"},
inventory_image = "vessels_drinking_glass_inv.png",
wield_image = "vessels_drinking_glass.png",
paramtype = "light",
is_ground_content = false,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
},
groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
sounds = default.node_sound_glass_defaults(),
})
minetest.register_craft( {
output = "vessels:drinking_glass 14",
recipe = {
{"default:glass", "", "default:glass"},
{"default:glass", "", "default:glass"},
{"default:glass", "default:glass", "default:glass"}
}
})
minetest.register_node("vessels:steel_bottle", {
description = S("Empty Heavy Steel Bottle"),
drawtype = "plantlike",
tiles = {"vessels_steel_bottle.png"},
inventory_image = "vessels_steel_bottle.png",
wield_image = "vessels_steel_bottle.png",
paramtype = "light",
is_ground_content = false,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25}
},
groups = {vessel = 1, dig_immediate = 3, attached_node = 1},
sounds = default.node_sound_defaults(),
})
minetest.register_craft( {
output = "vessels:steel_bottle 5",
recipe = {
{"default:steel_ingot", "", "default:steel_ingot"},
{"default:steel_ingot", "", "default:steel_ingot"},
{"", "default:steel_ingot", ""}
}
})
-- Glass and steel recycling
minetest.register_craftitem("vessels:glass_fragments", {
description = S("Glass Fragments"),
inventory_image = "vessels_glass_fragments.png",
})
minetest.register_craft( {
type = "shapeless",
output = "vessels:glass_fragments",
recipe = {
"vessels:glass_bottle",
"vessels:glass_bottle",
},
})
minetest.register_craft( {
type = "shapeless",
output = "vessels:glass_fragments",
recipe = {
"vessels:drinking_glass",
"vessels:drinking_glass",
},
})
minetest.register_craft({
type = "cooking",
output = "default:glass",
recipe = "vessels:glass_fragments",
})
minetest.register_craft( {
type = "cooking",
output = "default:steel_ingot",
recipe = "vessels:steel_bottle",
})
minetest.register_craft({
type = "fuel",
recipe = "vessels:shelf",
burntime = 30,
})
-- Register glass fragments as dungeon loot
if minetest.global_exists("dungeon_loot") then
dungeon_loot.register({
name = "vessels:glass_fragments", chance = 0.35, count = {1, 4}
})
end