mirror of
https://github.com/minetest-mods/craftguide.git
synced 2024-12-14 02:30:17 +01:00
Some cleanup with recipes caching
This commit is contained in:
parent
2771ec12f5
commit
89979a8610
47
init.lua
47
init.lua
@ -7,6 +7,7 @@ local searches = {}
|
|||||||
local recipes_cache = {}
|
local recipes_cache = {}
|
||||||
local usages_cache = {}
|
local usages_cache = {}
|
||||||
local fuel_cache = {}
|
local fuel_cache = {}
|
||||||
|
local cook_cache = {}
|
||||||
local toolrepair
|
local toolrepair
|
||||||
|
|
||||||
local progressive_mode = core.settings:get_bool "craftguide_progressive_mode"
|
local progressive_mode = core.settings:get_bool "craftguide_progressive_mode"
|
||||||
@ -604,7 +605,7 @@ local function cache_usages(item)
|
|||||||
local fuel = {
|
local fuel = {
|
||||||
type = "fuel",
|
type = "fuel",
|
||||||
items = {item},
|
items = {item},
|
||||||
replacements = fuel_cache.replacements[item],
|
replacements = fuel_cache[item].replacements,
|
||||||
}
|
}
|
||||||
|
|
||||||
usages_cache[item] = table_merge(usages_cache[item] or {}, {fuel})
|
usages_cache[item] = table_merge(usages_cache[item] or {}, {fuel})
|
||||||
@ -686,7 +687,21 @@ local function cache_drops(name, drop)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function cache_recipes(item)
|
local function cache_recipes(item)
|
||||||
recipes_cache[item] = get_all_recipes(item)
|
local recipes = get_all_recipes(item)
|
||||||
|
|
||||||
|
if recipes then
|
||||||
|
recipes_cache[item] = {}
|
||||||
|
for i = 1, #recipes do
|
||||||
|
local rcp = recipes[i]
|
||||||
|
if rcp.type ~= "cooking" then
|
||||||
|
insert(recipes_cache[item], rcp)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if cook_cache[item] then
|
||||||
|
recipes_cache[item] = table_merge(recipes_cache[item] or {}, {cook_cache[item]})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_recipes(item, data, player)
|
local function get_recipes(item, data, player)
|
||||||
@ -933,11 +948,12 @@ local function get_output_fs(lang_code, fs, rcp, shapeless, right, btn_size, _bt
|
|||||||
local unknown = not def or nil
|
local unknown = not def or nil
|
||||||
local desc = def and def.description
|
local desc = def and def.description
|
||||||
local weird = name ~= "" and desc and weird_desc(desc) or nil
|
local weird = name ~= "" and desc and weird_desc(desc) or nil
|
||||||
|
local burntime = fuel_cache[name] and fuel_cache[name].burntime
|
||||||
|
|
||||||
local infos = {
|
local infos = {
|
||||||
unknown = unknown,
|
unknown = unknown,
|
||||||
weird = weird,
|
weird = weird,
|
||||||
burntime = fuel_cache[name],
|
burntime = burntime,
|
||||||
repair = repairable(name),
|
repair = repairable(name),
|
||||||
rarity = rcp.rarity,
|
rarity = rcp.rarity,
|
||||||
tools = rcp.tools,
|
tools = rcp.tools,
|
||||||
@ -1058,12 +1074,13 @@ local function get_grid_fs(lang_code, fs, rcp, spacing)
|
|||||||
unknown = not groups and unknown or nil
|
unknown = not groups and unknown or nil
|
||||||
local desc = def and def.description
|
local desc = def and def.description
|
||||||
local weird = name ~= "" and desc and weird_desc(desc) or nil
|
local weird = name ~= "" and desc and weird_desc(desc) or nil
|
||||||
|
local burntime = fuel_cache[name] and fuel_cache[name].burntime
|
||||||
|
|
||||||
local infos = {
|
local infos = {
|
||||||
unknown = unknown,
|
unknown = unknown,
|
||||||
weird = weird,
|
weird = weird,
|
||||||
groups = groups,
|
groups = groups,
|
||||||
burntime = fuel_cache[name],
|
burntime = burntime,
|
||||||
cooktime = cooktime,
|
cooktime = cooktime,
|
||||||
replace = replace,
|
replace = replace,
|
||||||
}
|
}
|
||||||
@ -1429,8 +1446,6 @@ end)
|
|||||||
`core.register_craft` and do some reverse engineering.
|
`core.register_craft` and do some reverse engineering.
|
||||||
See engine's issues #4901 and #8920. ]]
|
See engine's issues #4901 and #8920. ]]
|
||||||
|
|
||||||
fuel_cache.replacements = {}
|
|
||||||
|
|
||||||
local old_register_craft = core.register_craft
|
local old_register_craft = core.register_craft
|
||||||
|
|
||||||
core.register_craft = function(def)
|
core.register_craft = function(def)
|
||||||
@ -1454,22 +1469,17 @@ core.register_craft = function(def)
|
|||||||
for i = 1, #output do
|
for i = 1, #output do
|
||||||
local name = output[i]
|
local name = output[i]
|
||||||
|
|
||||||
if def.type ~= "fuel" then
|
|
||||||
def.items = {}
|
|
||||||
end
|
|
||||||
|
|
||||||
if def.type == "fuel" then
|
if def.type == "fuel" then
|
||||||
fuel_cache[name] = def.burntime
|
fuel_cache[name] = {
|
||||||
fuel_cache.replacements[name] = def.replacements
|
burntime = def.burntime,
|
||||||
|
replacements = def.replacements,
|
||||||
|
}
|
||||||
|
|
||||||
elseif def.type == "cooking" then
|
elseif def.type == "cooking" then
|
||||||
def.width = def.cooktime
|
def.width = def.cooktime
|
||||||
def.cooktime = nil
|
def.items = {def.recipe}
|
||||||
def.items[1] = def.recipe
|
def.recipe, def.cooktime = nil, nil
|
||||||
def.recipe = nil
|
cook_cache[name] = def
|
||||||
|
|
||||||
recipes_cache[name] = recipes_cache[name] or {}
|
|
||||||
insert(recipes_cache[name], 1, def)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1560,7 +1570,6 @@ local function get_init_items()
|
|||||||
local post_data = {
|
local post_data = {
|
||||||
recipes = recipes_cache,
|
recipes = recipes_cache,
|
||||||
usages = usages_cache,
|
usages = usages_cache,
|
||||||
fuel = fuel_cache,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
http.fetch_async{
|
http.fetch_async{
|
||||||
|
Loading…
Reference in New Issue
Block a user