From e44dd3e74b28aae4cb353f567e8ba7cd22e03699 Mon Sep 17 00:00:00 2001 From: LeMagnesium Date: Thu, 26 Nov 2015 22:27:29 +0100 Subject: [PATCH] [pclasses] Vacuum three times : main, armor and detached - See #253 --- mods/pclasses/api.lua | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/mods/pclasses/api.lua b/mods/pclasses/api.lua index 60d28d68..448f1d6a 100755 --- a/mods/pclasses/api.lua +++ b/mods/pclasses/api.lua @@ -116,38 +116,38 @@ end -- Determination and reserved items tick -- ------------------------------------------- -local function vacuum_inventory(name, inv, invname) +local function vacuum_inventory(name, inv, invname, bury) local ref = minetest.get_player_by_name(name) for i = 1, inv:get_size(invname) do local stack = inv:get_stack(invname, i) if pclasses.data.reserved_items[stack:get_name()] then if not pclasses.api.util.can_have_item(name, stack:get_name()) then inv:set_stack(invname, i, "") - local grave_inv = pclasses.api.create_graveyard_inventory(ref) - if grave_inv and grave_inv:room_for_item("graveyard", stack) then - grave_inv:add_item("graveyard", stack) - inv:add_item("graveyard", stack) - -- ^ Because add_item doesn't trigger on_put, nonsense - else - minetest.add_item(ref:getpos(), stack) + if bury then + local grave_inv = pclasses.api.create_graveyard_inventory(ref) + if grave_inv and grave_inv:room_for_item("graveyard", stack) then + grave_inv:add_item("graveyard", stack) + inv:add_item("graveyard", stack) + -- ^ Because add_item doesn't trigger on_put, nonsense + else + minetest.add_item(ref:getpos(), stack) + end end end end end end - local function tick() for id, ref in ipairs(minetest.get_connected_players()) do local name = ref:get_player_name() local armor_inv = minetest.get_inventory({type = "detached", name = name .. "_armor"}) local inv = ref:get_inventory() - vacuum_inventory(name, inv, "main") - vacuum_inventory(name, inv, "armor") - -- Hack the hack - for i = 1, armor_inv:get_size("armor") do - armor_inv:set_stack("armor", i, inv:get_stack("armor", i)) - end + + vacuum_inventory(name, inv, "main", true) + vacuum_inventory(name, inv, "armor", true) + vacuum_inventory(name, armor_inv, "armor", false) -- Don't move to the graveyard + armor:set_player_armor(ref) armor:update_inventory(ref) end