-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
88 lines (76 loc) · 2.13 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
local function get_slot(x, y, size, texture)
local t = "image[" .. x - size .. "," .. y - size .. ";" .. 1 + (size * 2) ..
"," .. 1 + (size * 2) .. ";" .. (texture and texture or "mcl_formspec_itemslot.png") .. "]"
return t
end
local function get_itemslot_bg_v4(x, y, w, h, size, texture)
if not size then
size = 0.05
end
local out = ""
for i = 0, w - 1, 1 do
for j = 0, h - 1, 1 do
out = out .. get_slot(x + i + (i * 0.25), y + j + (j * 0.25), size, texture)
end
end
return out
end
local function show_formspec(param)
local name = minetest.localplayer:get_name()
local inv = minetest.get_inventory("player:"..name)
local dlists = ""
local i = 1
local idx = 1
for k,v in pairs(inv) do
if not param or param == "" then
param = k
end
dlists = dlists .. k .. ","
if k == param then idx = i end
i = i + 1
end
dlists = dlists:sub(1, -2)
if inv[param] then
local x = 0
local y = 1
for k,v in pairs(inv[param]) do
if x < 9 then
x = x + 1
elseif y < 3 then
y = y + 1
end
end
local fs = table.concat({
"formspec_version[4]",
"size[11.75,12.425]",
"label[0.375,0.375;Show Inv List]",
"dropdown[8,0.175;3,1;select_list;"..dlists..";"..idx.."]",
get_itemslot_bg_v4(0.375, 1.75, x, y),
"list[current_player;"..param..";0.375,1.75;"..x..","..y..";]",
"label[0.375,6.7;Inventory]",
get_itemslot_bg_v4(0.375, 7.1, 9, 3),
"list[current_player;main;0.375,7.1;9,3;9]",
get_itemslot_bg_v4(0.375, 11.05, 9, 1),
"list[current_player;main;0.375,11.05;9,1;]",
"listring[current_player;"..param.."]",
"listring[current_player;main]",
})
minetest.show_formspec("invutil_invlist", fs)
return true
else
return false, "List doesn't exists"
end
end
-- Register cheat menu entry in dragonfire
if minetest.register_cheat then
minetest.register_cheat("OpenInvLists", "Inventory", show_formspec)
end
minetest.register_chatcommand("openlist", {func=function(param)
return show_formspec(param)
end})
minetest.register_on_formspec_input(function(formname, fields)
if formname ~= 'invutil_invlist' then return end
if fields.select_list then
show_formspec(fields.select_list)
end
end)