Skip to content

Commit

Permalink
Categories: remove unknown items after start
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SmallJoker committed Mar 17, 2024
1 parent 921a6d7 commit b5de18b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
21 changes: 21 additions & 0 deletions api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b5de18b

Please sign in to comment.