2013-02-02 11:12:10 +01:00
|
|
|
|
|
|
|
-- Create detached creative inventory after loading all mods
|
|
|
|
minetest.after(0.01, function()
|
|
|
|
unified_inventory.items_list = {}
|
2013-09-24 22:52:27 +02:00
|
|
|
for name, def in pairs(minetest.registered_items) do
|
|
|
|
if (not def.groups.not_in_creative_inventory or
|
|
|
|
def.groups.not_in_creative_inventory == 0) and
|
|
|
|
def.description and def.description ~= "" then
|
2013-02-02 11:12:10 +01:00
|
|
|
table.insert(unified_inventory.items_list, name)
|
2013-09-24 22:52:27 +02:00
|
|
|
local recipes = minetest.get_all_craft_recipes(name)
|
|
|
|
unified_inventory.crafts_table[name] = recipes or {}
|
2013-02-02 11:12:10 +01:00
|
|
|
end
|
|
|
|
end
|
2013-06-30 07:12:02 +02:00
|
|
|
--print(dump(unified_inventory.crafts_table))
|
2013-02-02 11:12:10 +01:00
|
|
|
table.sort(unified_inventory.items_list)
|
|
|
|
unified_inventory.items_list_size = #unified_inventory.items_list
|
2013-09-24 22:52:27 +02:00
|
|
|
print("Unified Inventory. inventory size: "..#unified_inventory.items_list)
|
2013-02-02 11:12:10 +01:00
|
|
|
end)
|
|
|
|
|
2013-02-02 21:29:59 +01:00
|
|
|
|
2013-09-24 22:52:27 +02:00
|
|
|
-- load_home
|
|
|
|
local function load_home()
|
|
|
|
local input = io.open(unified_inventory.home_filename, "r")
|
|
|
|
if input then
|
|
|
|
while true do
|
|
|
|
local x = input:read("*n")
|
|
|
|
if x == nil then
|
|
|
|
break
|
2013-02-02 11:12:10 +01:00
|
|
|
end
|
2013-09-24 22:52:27 +02:00
|
|
|
local y = input:read("*n")
|
|
|
|
local z = input:read("*n")
|
|
|
|
local name = input:read("*l")
|
|
|
|
unified_inventory.home_pos[name:sub(2)] = {x = x, y = y, z = z}
|
2013-02-02 11:12:10 +01:00
|
|
|
end
|
2013-09-24 22:52:27 +02:00
|
|
|
io.close(input)
|
|
|
|
else
|
|
|
|
unified_inventory.home_pos = {}
|
2013-02-02 11:12:10 +01:00
|
|
|
end
|
|
|
|
end
|
2013-09-24 22:52:27 +02:00
|
|
|
load_home()
|
2013-02-02 11:12:10 +01:00
|
|
|
|
2013-09-24 22:52:27 +02:00
|
|
|
function unified_inventory.set_home(player, pos)
|
2013-02-02 11:12:10 +01:00
|
|
|
local player_name = player:get_player_name()
|
2013-09-24 22:52:27 +02:00
|
|
|
unified_inventory.home_pos[player_name] = pos
|
2013-02-02 11:12:10 +01:00
|
|
|
-- save the home data from the table to the file
|
2013-09-24 22:52:27 +02:00
|
|
|
local output = io.open(unified_inventory.home_filename, "w")
|
|
|
|
for k, v in pairs(unified_inventory.home_pos) do
|
2013-02-02 11:12:10 +01:00
|
|
|
if v ~= nil then
|
2013-09-24 22:52:27 +02:00
|
|
|
output:write(math.floor(v.x).." "
|
|
|
|
..math.floor(v.y).." "
|
|
|
|
..math.floor(v.z).." "
|
|
|
|
..k.."\n")
|
2013-02-02 11:12:10 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
io.close(output)
|
|
|
|
end
|
|
|
|
|
2013-09-24 22:52:27 +02:00
|
|
|
function unified_inventory.go_home(player)
|
|
|
|
local pos = unified_inventory.home_pos[player:get_player_name()]
|
|
|
|
if pos ~= nil then
|
2013-02-02 11:12:10 +01:00
|
|
|
player:setpos(pos)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-24 22:52:27 +02:00
|
|
|
-- register_craft
|
|
|
|
function unified_inventory.register_craft(options)
|
|
|
|
if not options.output then
|
|
|
|
return
|
2013-02-02 11:12:10 +01:00
|
|
|
end
|
2013-09-24 22:52:27 +02:00
|
|
|
local itemstack = ItemStack(options.output)
|
|
|
|
if itemstack:is_empty() then
|
|
|
|
return
|
2013-02-02 11:12:10 +01:00
|
|
|
end
|
2013-09-24 22:52:27 +02:00
|
|
|
unified_inventory.crafts_table[itemstack:get_name()] =
|
|
|
|
unified_inventory.crafts_table[itemstack:get_name()] or {}
|
2013-07-08 22:53:44 +02:00
|
|
|
|
2013-09-24 22:52:27 +02:00
|
|
|
table.insert(unified_inventory.crafts_table[itemstack:get_name()], options)
|
2013-02-02 11:12:10 +01:00
|
|
|
end
|
|
|
|
|
2013-09-24 22:52:27 +02:00
|
|
|
function unified_inventory.register_page(name, def)
|
|
|
|
unified_inventory.pages[name] = def
|
2013-02-02 11:12:10 +01:00
|
|
|
end
|
2013-06-30 07:12:02 +02:00
|
|
|
|
2013-09-24 22:52:27 +02:00
|
|
|
function unified_inventory.register_button(name, def)
|
|
|
|
if not def.action then
|
|
|
|
def.action = function(player)
|
|
|
|
unified_inventory.set_inventory_formspec(player, name)
|
2013-06-30 07:12:02 +02:00
|
|
|
end
|
|
|
|
end
|
2013-09-24 22:52:27 +02:00
|
|
|
|
|
|
|
def.name = name
|
|
|
|
|
|
|
|
table.insert(unified_inventory.buttons, def)
|
2013-06-30 07:12:02 +02:00
|
|
|
end
|
|
|
|
|
2013-09-24 22:52:27 +02:00
|
|
|
function unified_inventory.is_creative(playername)
|
|
|
|
if minetest.check_player_privs(playername, {creative=true}) or
|
|
|
|
minetest.setting_getbool("creative_mode") then
|
|
|
|
return true
|
2013-06-30 07:12:02 +02:00
|
|
|
end
|
|
|
|
end
|