Cache groups (testing needed)

This commit is contained in:
Jean-Patrick Guerrero
2022-06-18 19:47:23 +02:00
parent cf5f18e1c1
commit f0f94017da
5 changed files with 29 additions and 11 deletions

View File

@ -23,10 +23,22 @@ local function cache_fuel(item)
end
end
local function get_item_usages(item, recipe, added)
local groups = extract_groups(item)
local function cache_groups(groupname, groups)
i3.groups[groupname] = {}
i3.groups[groupname].groups = groups
i3.groups[groupname].items = groups_to_items(groups, true)
end
local function get_item_usages(item, recipe, added)
if is_group(item) then
local groupname = item:sub(7)
local group_cache = i3.groups[groupname]
local groups = group_cache and group_cache.groups or extract_groups(item)
if not group_cache then
cache_groups(groupname, groups)
end
if groups then
for name, def in pairs(reg_items) do
if not added[name] and valid_item(def) and item_has_groups(def.groups, groups) then
local usage = copy(recipe)