2015-08-01 19:26:50 +02:00
|
|
|
------------------------
|
|
|
|
-- PClasses' inventory
|
|
|
|
--
|
|
|
|
|
|
|
|
-- Inventory for 'dead' items
|
|
|
|
pclasses.api.create_graveyard_inventory = function(player)
|
|
|
|
local pname = player:get_player_name()
|
2015-08-20 17:11:46 +02:00
|
|
|
local grave_inv = minetest.get_inventory({type = "detached", name = pname .. "_graveyard"})
|
|
|
|
if grave_inv then
|
|
|
|
return grave_inv
|
|
|
|
end
|
2015-08-01 19:26:50 +02:00
|
|
|
local player_inv = minetest.get_inventory({type = "player", name = pname})
|
2015-08-20 17:11:46 +02:00
|
|
|
grave_inv = minetest.create_detached_inventory(pname .. "_graveyard", {
|
2015-08-01 19:26:50 +02:00
|
|
|
on_take = function(inv, listname, index, stack, player)
|
|
|
|
player_inv:set_stack(listname, index, nil)
|
|
|
|
end,
|
|
|
|
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
|
|
|
local stack = inv:get_stack(to_list, to_index)
|
|
|
|
player_inv:set_stack(to_list, to_index, stack)
|
|
|
|
player_inv:set_stack(from_list, from_index, nil)
|
|
|
|
end,
|
|
|
|
allow_take = function(inv, listname, index, stack, player)
|
2015-11-25 23:21:15 +01:00
|
|
|
player_inv:set_stack(listname, index, nil)
|
|
|
|
return stack:get_count()
|
2015-08-01 19:26:50 +02:00
|
|
|
end,
|
|
|
|
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
|
|
|
return 0
|
|
|
|
end,
|
|
|
|
allow_put = function(inv, listname, index, stack, player)
|
|
|
|
return 0
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
grave_inv:set_size("graveyard", 7*8)
|
|
|
|
player_inv:set_size("graveyard", 7*8)
|
|
|
|
for i = 1,56 do
|
|
|
|
local stack = player_inv:get_stack("graveyard", i)
|
|
|
|
grave_inv:set_stack("graveyard", i, stack)
|
|
|
|
end
|
2015-08-02 15:18:12 +02:00
|
|
|
return grave_inv
|
2015-08-01 19:26:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
unified_inventory.register_button("graveyard", {
|
|
|
|
type = "image",
|
|
|
|
image = "pclasses_grave_button.png",
|
|
|
|
tooltip = "Item Graveyard",
|
|
|
|
})
|
|
|
|
|
|
|
|
unified_inventory.register_page("graveyard", {
|
|
|
|
get_formspec = function(player)
|
|
|
|
local pname = player:get_player_name()
|
|
|
|
local form = "label[0,0;Graveyard]" ..
|
2015-08-26 15:29:40 +02:00
|
|
|
"list[detached:" .. pname .. "_graveyard;graveyard;0.5,0.7;7,8]"
|
2015-08-01 19:26:50 +02:00
|
|
|
return {formspec = form, draw_inventory = false}
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2015-08-26 15:29:40 +02:00
|
|
|
minetest.register_chatcommand("clear_graveyard", {
|
|
|
|
description = "Clear Graveyard Inventory",
|
|
|
|
privs = {},
|
|
|
|
func = function(name, param)
|
|
|
|
local grave_inv = minetest.get_inventory({type = "detached", name = name .. "_graveyard"})
|
|
|
|
grave_inv:set_list("graveyard", {})
|
2015-08-26 16:12:29 +02:00
|
|
|
minetest.get_player_by_name(name):get_inventory():set_list("graveyard", {})
|
2015-08-26 15:29:40 +02:00
|
|
|
return true, "Graveyard flushed"
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2015-08-01 20:28:12 +02:00
|
|
|
function pclasses.api.vacuum_graveyard(player)
|
|
|
|
local pname = player:get_player_name()
|
|
|
|
local grave_inv = minetest.get_inventory({type = "detached", name = pname .. "_graveyard"})
|
|
|
|
local player_inv = minetest.get_inventory({type = "player", name = pname})
|
|
|
|
|
2015-08-01 23:55:44 +02:00
|
|
|
if not grave_inv then return end
|
|
|
|
|
2015-08-01 20:28:12 +02:00
|
|
|
for i = 1,7*8 do
|
|
|
|
local stack = grave_inv:get_stack("graveyard", i)
|
2015-08-02 21:25:31 +02:00
|
|
|
if pclasses.data.reserved_items[stack:get_name()] and pclasses.api.util.can_have_item(pname, stack:get_name()) then
|
2015-08-01 20:28:12 +02:00
|
|
|
grave_inv:set_stack("graveyard", i, nil)
|
|
|
|
player_inv:set_stack("graveyard", i, nil)
|
|
|
|
if player_inv:room_for_item("main", stack) then
|
|
|
|
player_inv:add_item("main", stack)
|
|
|
|
else
|
2015-08-20 17:11:46 +02:00
|
|
|
minetest.add_item(player:getpos(), stack)
|
2015-08-01 20:28:12 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|