mirror of
https://github.com/minetest-mods/unified_inventory.git
synced 2024-12-27 03:00:28 +01:00
Categories: remove unknown items after start
This avoids runtime errors caused by removed items or such that were not registered at all but listed by default in a pre-defined category.
This commit is contained in:
parent
921a6d76ee
commit
b5de18b196
21
api.lua
21
api.lua
@ -184,6 +184,27 @@ minetest.after(0.01, function()
|
||||
ui.crafts_for.recipe[outputitemname] = new_recipe_list
|
||||
end
|
||||
|
||||
-- Remove unknown items from all categories
|
||||
local total_removed = 0
|
||||
for cat_name, cat_def in pairs(ui.registered_category_items) do
|
||||
for itemname, exists in pairs(cat_def) do
|
||||
if exists and not minetest.registered_items[itemname] then
|
||||
total_removed = total_removed + 1
|
||||
--[[
|
||||
-- For analysis
|
||||
minetest.log("warning", "[unified_inventory] Removed item '"
|
||||
.. itemname .. "' from category '" .. cat_name
|
||||
.. "'. Reason: item not registered")
|
||||
]]
|
||||
cat_def[itemname] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
if total_removed > 0 then
|
||||
minetest.log("info", "[unified_inventory] Removed " .. total_removed ..
|
||||
" unknown items from the categories.")
|
||||
end
|
||||
|
||||
for _, callback in ipairs(ui.initialized_callbacks) do
|
||||
callback()
|
||||
end
|
||||
|
@ -368,6 +368,10 @@ function ui.apply_filter(player, filter, search_dir)
|
||||
local groups = lfilter:sub(7):split(",")
|
||||
ffilter = function(name)
|
||||
local def = registered_items[name]
|
||||
if not def then
|
||||
return false
|
||||
end
|
||||
|
||||
for _, group in ipairs(groups) do
|
||||
if not def.groups[group]
|
||||
or def.groups[group] <= 0 then
|
||||
@ -383,6 +387,10 @@ function ui.apply_filter(player, filter, search_dir)
|
||||
|
||||
ffilter = function(name)
|
||||
local def = registered_items[name]
|
||||
if not def then
|
||||
return false
|
||||
end
|
||||
|
||||
local lname = string.lower(name)
|
||||
local ldesc = string.lower(def.description)
|
||||
local llocaldesc = minetest.get_translated_string
|
||||
|
Loading…
Reference in New Issue
Block a user