mirror of
https://github.com/minetest-mods/craftguide.git
synced 2024-11-15 22:20:17 +01:00
get_inv_items improvements
Check craft list, don't add duplicates, and only add registered items
This commit is contained in:
parent
d5556ab964
commit
48856e0d23
21
init.lua
21
init.lua
|
@ -472,13 +472,21 @@ local function get_item_usages(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_inv_items(player)
|
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 = {}
|
local inv_items = {}
|
||||||
|
|
||||||
for i = 1, #invlist do
|
for i = 1, #stacks do
|
||||||
local stack = invlist[i]
|
local stack = stacks[i]
|
||||||
if not stack:is_empty() then
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -492,14 +500,11 @@ local function progressive_show_recipe(recipe, inv_items)
|
||||||
if item:sub(1,6) == "group:" then
|
if item:sub(1,6) == "group:" then
|
||||||
local groups = extract_groups(item)
|
local groups = extract_groups(item)
|
||||||
for i = 1, inv_items_size do
|
for i = 1, inv_items_size do
|
||||||
local item_def = reg_items[inv_items[i]]
|
local item_groups = reg_items[inv_items[i]].groups
|
||||||
if item_def then
|
|
||||||
local item_groups = item_def.groups
|
|
||||||
if item_has_groups(item_groups, groups) then
|
if item_has_groups(item_groups, groups) then
|
||||||
item_in_inv = true
|
item_in_inv = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
else
|
else
|
||||||
for i = 1, inv_items_size do
|
for i = 1, inv_items_size do
|
||||||
if inv_items[i] == item then
|
if inv_items[i] == item then
|
||||||
|
|
Loading…
Reference in New Issue
Block a user