commit | author | age
|
a4a3c2
|
1 |
|
R |
2 |
-- Create detached creative inventory after loading all mods |
|
3 |
minetest.after(0.01, function() |
|
4 |
unified_inventory.items_list = {} |
310761
|
5 |
for name, def in pairs(minetest.registered_items) do |
S |
6 |
if (not def.groups.not_in_creative_inventory or |
|
7 |
def.groups.not_in_creative_inventory == 0) and |
|
8 |
def.description and def.description ~= "" then |
a4a3c2
|
9 |
table.insert(unified_inventory.items_list, name) |
310761
|
10 |
local recipes = minetest.get_all_craft_recipes(name) |
S |
11 |
unified_inventory.crafts_table[name] = recipes or {} |
a4a3c2
|
12 |
end |
R |
13 |
end |
8e03d7
|
14 |
--print(dump(unified_inventory.crafts_table)) |
a4a3c2
|
15 |
table.sort(unified_inventory.items_list) |
R |
16 |
unified_inventory.items_list_size = #unified_inventory.items_list |
310761
|
17 |
print("Unified Inventory. inventory size: "..#unified_inventory.items_list) |
a4a3c2
|
18 |
end) |
R |
19 |
|
|
20 |
|
|
21 |
-- load_home |
310761
|
22 |
local function load_home() |
S |
23 |
local input = io.open(unified_inventory.home_filename, "r") |
|
24 |
if input then |
|
25 |
while true do |
|
26 |
local x = input:read("*n") |
|
27 |
if x == nil then |
|
28 |
break |
|
29 |
end |
|
30 |
local y = input:read("*n") |
|
31 |
local z = input:read("*n") |
|
32 |
local name = input:read("*l") |
|
33 |
unified_inventory.home_pos[name:sub(2)] = {x = x, y = y, z = z} |
|
34 |
end |
|
35 |
io.close(input) |
|
36 |
else |
|
37 |
unified_inventory.home_pos = {} |
|
38 |
end |
a4a3c2
|
39 |
end |
310761
|
40 |
load_home() |
a4a3c2
|
41 |
|
310761
|
42 |
function unified_inventory.set_home(player, pos) |
S |
43 |
local player_name = player:get_player_name() |
|
44 |
unified_inventory.home_pos[player_name] = pos |
a4a3c2
|
45 |
-- save the home data from the table to the file |
310761
|
46 |
local output = io.open(unified_inventory.home_filename, "w") |
S |
47 |
for k, v in pairs(unified_inventory.home_pos) do |
a4a3c2
|
48 |
if v ~= nil then |
310761
|
49 |
output:write(math.floor(v.x).." " |
S |
50 |
..math.floor(v.y).." " |
|
51 |
..math.floor(v.z).." " |
|
52 |
..k.."\n") |
a4a3c2
|
53 |
end |
R |
54 |
end |
|
55 |
io.close(output) |
|
56 |
end |
|
57 |
|
310761
|
58 |
function unified_inventory.go_home(player) |
S |
59 |
local pos = unified_inventory.home_pos[player:get_player_name()] |
|
60 |
if pos ~= nil then |
a4a3c2
|
61 |
player:setpos(pos) |
R |
62 |
end |
|
63 |
end |
|
64 |
|
8e03d7
|
65 |
-- register_craft |
310761
|
66 |
function unified_inventory.register_craft(options) |
S |
67 |
if not options.output then |
8e03d7
|
68 |
return |
R |
69 |
end |
|
70 |
local itemstack = ItemStack(options.output) |
|
71 |
if itemstack:is_empty() then |
|
72 |
return |
|
73 |
end |
310761
|
74 |
unified_inventory.crafts_table[itemstack:get_name()] = |
S |
75 |
unified_inventory.crafts_table[itemstack:get_name()] or {} |
|
76 |
|
|
77 |
table.insert(unified_inventory.crafts_table[itemstack:get_name()], options) |
|
78 |
end |
|
79 |
|
|
80 |
function unified_inventory.register_page(name, def) |
|
81 |
unified_inventory.pages[name] = def |
|
82 |
end |
|
83 |
|
|
84 |
function unified_inventory.register_button(name, def) |
|
85 |
if not def.action then |
|
86 |
def.action = function(player) |
|
87 |
unified_inventory.set_inventory_formspec(player, name) |
|
88 |
end |
8e03d7
|
89 |
end |
310761
|
90 |
|
S |
91 |
def.name = name |
|
92 |
|
|
93 |
table.insert(unified_inventory.buttons, def) |
|
94 |
end |
|
95 |
|
|
96 |
function unified_inventory.is_creative(playername) |
|
97 |
if minetest.check_player_privs(playername, {creative=true}) or |
|
98 |
minetest.setting_getbool("creative_mode") then |
|
99 |
return true |
|
100 |
end |
8e03d7
|
101 |
end |