mirror of
https://github.com/minetest-mods/craftguide.git
synced 2024-11-22 19:03:43 +01:00
Items with no recipes but with usages are shown
This commit is contained in:
parent
22a85f50c1
commit
a2e4f20791
46
init.lua
46
init.lua
@ -271,7 +271,7 @@ local function groups_item_in_recipe(item, recipe)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_item_usages(item)
|
local function get_usages(item)
|
||||||
local usages, c = {}, 0
|
local usages, c = {}, 0
|
||||||
|
|
||||||
for _, recipes in pairs(recipes_cache) do
|
for _, recipes in pairs(recipes_cache) do
|
||||||
@ -329,7 +329,13 @@ local function cache_recipes(output)
|
|||||||
|
|
||||||
if #recipes > 0 then
|
if #recipes > 0 then
|
||||||
recipes_cache[output] = recipes
|
recipes_cache[output] = recipes
|
||||||
return true
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function cache_usages(item)
|
||||||
|
local usages = get_usages(item)
|
||||||
|
if #usages > 0 then
|
||||||
|
usages_cache[item] = usages
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -350,7 +356,7 @@ local function get_recipes(item, data, player)
|
|||||||
|
|
||||||
if data.show_usages then
|
if data.show_usages then
|
||||||
recipes = apply_recipe_filters(usages_cache[item], player)
|
recipes = apply_recipe_filters(usages_cache[item], player)
|
||||||
if #recipes == 0 then
|
if recipes and #recipes == 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -790,28 +796,38 @@ local function reset_data(data)
|
|||||||
data.items = data.items_raw
|
data.items = data.items_raw
|
||||||
end
|
end
|
||||||
|
|
||||||
local function cache_usages()
|
local function check_item(def)
|
||||||
for i = 1, #init_items do
|
return not (def.groups.not_in_craft_guide == 1 or
|
||||||
local item = init_items[i]
|
def.groups.not_in_creative_inventory == 1) and
|
||||||
usages_cache[item] = get_item_usages(item)
|
def.description and def.description ~= ""
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_init_items()
|
local function get_init_items()
|
||||||
local c = 0
|
local items, c = {}, 0
|
||||||
|
|
||||||
for name, def in pairs(reg_items) do
|
for name, def in pairs(reg_items) do
|
||||||
local is_fuel = cache_fuel(name)
|
if check_item(def) then
|
||||||
if not (def.groups.not_in_craft_guide == 1 or
|
cache_fuel(name)
|
||||||
def.groups.not_in_creative_inventory == 1) and
|
cache_recipes(name)
|
||||||
def.description and def.description ~= "" and
|
|
||||||
(cache_recipes(name) or is_fuel) then
|
c = c + 1
|
||||||
|
items[c] = name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
c = 0
|
||||||
|
|
||||||
|
for i = 1, #items do
|
||||||
|
local name = items[i]
|
||||||
|
cache_usages(name)
|
||||||
|
|
||||||
|
if recipes_cache[name] or usages_cache[name] then
|
||||||
c = c + 1
|
c = c + 1
|
||||||
init_items[c] = name
|
init_items[c] = name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
sort(init_items)
|
sort(init_items)
|
||||||
cache_usages()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_receive_fields(player, fields)
|
local function on_receive_fields(player, fields)
|
||||||
|
Loading…
Reference in New Issue
Block a user