Add i3.get_recipes()

This commit is contained in:
Jean-Patrick Guerrero 2021-10-18 21:21:33 +02:00
parent b6d36e59b0
commit f8ac9c45d1
2 changed files with 13 additions and 3 deletions

4
API.md
View File

@ -241,6 +241,10 @@ Returns a map of search filters, indexed by name.
### Miscellaneous
#### `i3.get_recipes(item)`
Returns a table of recipes and usages of given `item` name.
#### `i3.export_url`
If set, the mod will export all the cached recipes and usages in a JSON format

View File

@ -807,6 +807,13 @@ local function cache_recipes(item)
end
end
function i3.get_recipes(item)
return {
recipes = recipes_cache[item],
usages = usages_cache[item]
}
end
local function get_recipes(player, item)
local clean_item = reg_aliases[item] or item
local recipes = recipes_cache[clean_item]
@ -2966,7 +2973,7 @@ local function init_backpack(player)
local empty = _inv:get_stack(listname, 1):is_empty()
local item_group = minetest.get_item_group(stack:get_name(), "bag")
if empty and item_group > 0 and item_group < 4 then
if empty and item_group > 0 and item_group <= #BAG_SIZES then
return 1
end
@ -2997,7 +3004,6 @@ local function init_backpack(player)
data.bag_size = nil
inv:set_size("main", INV_SIZE)
set_fs(player)
end,
})