diff --git a/mods/runes/api.lua b/mods/runes/api.lua index 6ef36bdf..2c7470b7 100644 --- a/mods/runes/api.lua +++ b/mods/runes/api.lua @@ -205,8 +205,91 @@ runes.functions.register_amulet = function(name, desc, maxcount, manadiff) minetest.register_craftitem("runes:" .. name .. "_amulet", { description = desc, inventory_image = "runes_" .. name .. "_amulet.png", - groups = {amulet = 1}, + groups = {amulet = 1, rune = 1}, stack_max = maxcount, }) runes.datas.amulets[name] = manadiff end + +-- Inventory + +unified_inventory.register_button("runes", { + type = "image", + image = "runes_heal_major.png", +}) +unified_inventory.register_page("runes", { + get_formspec = function(player) + local name = player:get_player_name() + local formspec = "background[0,0.2;8,4;runes_rune_inventory.png]".. + "background[0,4.5;8,4;ui_wooden_chest_inventory.png]".. + "size[8,10]".. + "list[detached:"..name.."_runes;runes;0,0.2;8,4;]" + return {formspec=formspec} + end, +}) + +runes.functions.register_detached_inventory = function(player) + local name = player:get_player_name() + local player_inv = player:get_inventory() + local datafile = io.open(minetest.get_worldpath().."/runes/"..name.."_rune.inv", "r") + local rune_inv_data = {} + if datafile then + local line = datafile:read() + if line then + rune_inv_data = minetest.deserialize(line) + end + io.close(datafile) + end + local rune_inv = minetest.create_detached_inventory(name.."_runes",{ + on_put = function(inv, listname, index, stack, player) + player:get_inventory():set_stack(listname, index, stack) + armor:set_player_armor(player) + armor:update_inventory(player) + end, + on_take = function(inv, listname, index, stack, player) + player:get_inventory():set_stack(listname, index, nil) + armor:set_player_armor(player) + armor:update_inventory(player) + end, + allow_put = function(inv, listname, index, stack, player) + if minetest.get_item_group(stack:get_name(), "rune") > 0 then + return stack:get_count() + end + return 0 + end, + allow_take = function(inv, listname, index, stack, player) + return stack:get_count() + end, + allow_move = function(inv, from_list, from_index, to_list, to_index, count, player) + return count + end, + }) + rune_inv:set_size("runes", 8*4) + rune_inv:set_list("runes",rune_inv_data) + minetest.log("action","[runes] Rune inventory loaded for player " .. name) +end + +minetest.register_on_joinplayer(runes.functions.register_detached_inventory) + +runes.functions.save_detached_inventory = function(player) + local name = player:get_player_name() + local player_inv = player:get_inventory() + local datafile = io.open(minetest.get_worldpath().."/runes/"..name.."_rune.inv", "w") + local rune_inv_data = minetest.get_inventory({type = "detached", name=name.."_runes"}) + local translated_rune_data = {} + for index, data in pairs(rune_inv_data:get_list("runes")) do + translated_rune_data[index] = data:get_name() .. " " .. data:get_count() + end + if datafile then + datafile:write(minetest.serialize(translated_rune_data)) + end + io.close(datafile) + minetest.log("action", "[runes] Rune inventory saved for player " .. name) +end + +minetest.register_on_leaveplayer(runes.functions.save_detached_inventory) +minetest.register_on_shutdown(function() + for index, player in pairs(minetest.get_connected_players()) do + runes.functions.save_detached_inventory(player) + end +end) diff --git a/mods/runes/depends.txt b/mods/runes/depends.txt index 49bb81b0..66340fe7 100644 --- a/mods/runes/depends.txt +++ b/mods/runes/depends.txt @@ -1,2 +1,3 @@ default +unified_inventory mana diff --git a/mods/runes/textures/runes_rune_inventory.png b/mods/runes/textures/runes_rune_inventory.png new file mode 100755 index 00000000..145d9d22 Binary files /dev/null and b/mods/runes/textures/runes_rune_inventory.png differ