get_inv_items improvements

Check craft list, don't add duplicates, and only add registered items
This commit is contained in:
Paul Ouellette 2019-01-20 02:44:16 -05:00
parent d5556ab964
commit 48856e0d23

View File

@ -472,13 +472,21 @@ local function get_item_usages(item)
end
local function get_inv_items(player)
local invlist = player:get_inventory():get_list("main")
local inv = player:get_inventory()
local stacks = inv:get_list("main")
local craftlist = inv:get_list("craft")
for i = 1, #craftlist do
stacks[#stacks + 1] = craftlist[i]
end
local inv_items = {}
for i = 1, #invlist do
local stack = invlist[i]
for i = 1, #stacks do
local stack = stacks[i]
if not stack:is_empty() then
inv_items[#inv_items + 1] = stack:get_name()
local name = stack:get_name()
if not inv_items[name] and reg_items[name] then
inv_items[#inv_items + 1] = name
end
end
end
@ -492,12 +500,9 @@ local function progressive_show_recipe(recipe, inv_items)
if item:sub(1,6) == "group:" then
local groups = extract_groups(item)
for i = 1, inv_items_size do
local item_def = reg_items[inv_items[i]]
if item_def then
local item_groups = item_def.groups
if item_has_groups(item_groups, groups) then
item_in_inv = true
end
local item_groups = reg_items[inv_items[i]].groups
if item_has_groups(item_groups, groups) then
item_in_inv = true
end
end
else