mirror of
https://github.com/minetest-mods/unified_inventory.git
synced 2024-12-28 11:40:24 +01:00
Purge recipes with invalid ingredients
This commit is contained in:
parent
19e14aa21e
commit
88b3033477
15
api.lua
15
api.lua
@ -145,14 +145,18 @@ minetest.after(0.01, function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Step 1: group-indexed lookup table for items
|
-- Step 1: Initialize cache for looking up groups
|
||||||
unified_inventory.init_matching_cache()
|
unified_inventory.init_matching_cache()
|
||||||
|
|
||||||
-- Step 2: Find all matching items for the given spec (groups)
|
-- Step 2: Find all matching items for the given spec (groups)
|
||||||
local get_matching_spec_items = unified_inventory.get_matching_items
|
local get_matching_spec_items = unified_inventory.get_matching_items
|
||||||
|
|
||||||
for _, recipes in pairs(ui.crafts_for.recipe) do
|
for outputitemname, recipes in pairs(ui.crafts_for.recipe) do
|
||||||
-- List of crafts that return this item string (variable "_")
|
-- List of crafts that return this item string (variable "_")
|
||||||
|
|
||||||
|
-- Problem: The group cache must be initialized after all mods finished loading
|
||||||
|
-- thus, invalid recipes might be indexed. Hence perform filtering with `new_recipe_list`
|
||||||
|
local new_recipe_list = {}
|
||||||
for _, recipe in ipairs(recipes) do
|
for _, recipe in ipairs(recipes) do
|
||||||
local ingredient_items = {}
|
local ingredient_items = {}
|
||||||
for _, spec in pairs(recipe.items) do
|
for _, spec in pairs(recipe.items) do
|
||||||
@ -168,7 +172,14 @@ minetest.after(0.01, function()
|
|||||||
end
|
end
|
||||||
table.insert(ui.crafts_for.usage[name], recipe)
|
table.insert(ui.crafts_for.usage[name], recipe)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if next(ingredient_items) then
|
||||||
|
-- There's at least one known ingredient: mark as good recipe
|
||||||
|
-- PS: What whatll be done about partially incomplete recipes?
|
||||||
|
table.insert(new_recipe_list, recipe)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
ui.crafts_for.recipe[outputitemname] = new_recipe_list
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, callback in ipairs(ui.initialized_callbacks) do
|
for _, callback in ipairs(ui.initialized_callbacks) do
|
||||||
|
@ -24,7 +24,9 @@ Grouped by use-case, afterwards sorted alphabetically.
|
|||||||
Callbacks
|
Callbacks
|
||||||
---------
|
---------
|
||||||
|
|
||||||
Register a callback that will be run whenever a craft is registered via unified_inventory.register_craft:
|
Register a callback that will be run whenever a craft is registered via unified_inventory.register_craft.
|
||||||
|
This callback is run before any recipe ingredients checks, hence it is also executed on recipes that are
|
||||||
|
purged after all mods finished loading.
|
||||||
|
|
||||||
unified_inventory.register_on_craft_registered(
|
unified_inventory.register_on_craft_registered(
|
||||||
function (item_name, options)
|
function (item_name, options)
|
||||||
|
Loading…
Reference in New Issue
Block a user