Categories: Remove `not_in_creative_inventory` items

`unified_inventory.is_itemdef_listable` already prevents such items
being listed. They are not needed, thus removing them from the
categories in the first place does make sense.

Co-authored-by: SmallJoker <mk939@ymail.com>
This commit is contained in:
Niklp 2024-03-18 15:08:31 +01:00 committed by SmallJoker
parent b5de18b196
commit 2c9449b6e7
1 changed files with 13 additions and 3 deletions

16
api.lua
View File

@ -187,8 +187,9 @@ minetest.after(0.01, function()
-- 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
for itemname, _ in pairs(cat_def) do
local idef = minetest.registered_items[itemname]
if not idef then
total_removed = total_removed + 1
--[[
-- For analysis
@ -197,12 +198,21 @@ minetest.after(0.01, function()
.. "'. Reason: item not registered")
]]
cat_def[itemname] = nil
elseif not ui.is_itemdef_listable(idef) then
total_removed = total_removed + 1
--[[
-- For analysis
minetest.log("warning", "[unified_inventory] Removed item '"
.. itemname .. "' from category '" .. cat_name
.. "'. Reason: item is in 'not_in_creative_inventory' group")
]]
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.")
" items from the categories.")
end
for _, callback in ipairs(ui.initialized_callbacks) do