From 944674df0537541597db85b63cf329073cc35ef4 Mon Sep 17 00:00:00 2001 From: Matthew Nestor Date: Fri, 12 Aug 2022 09:58:23 -0400 Subject: [PATCH 1/2] handle basic table --- mods/HUD/craftguide/init.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mods/HUD/craftguide/init.lua b/mods/HUD/craftguide/init.lua index 7990ae3..0621e28 100644 --- a/mods/HUD/craftguide/init.lua +++ b/mods/HUD/craftguide/init.lua @@ -1359,7 +1359,16 @@ core.clear_craft = function(def) fuel_cache[def] = nil elseif is_table(def) then - return -- TODO + for item_name, item_recipes in pairs(recipes_cache) do + for recipe_index, recipe in pairs(item_recipes) do + for ingredient_index, ingredient in pairs(recipe.items) do + if (recipe.type == def.type) and (ingredient == def.recipe) then + table.remove(recipes_cache[item_name], recipe_index) + break + end + end + end + end end end From 00d73edb0cfee179b9f30a78ce507b741bbeca56 Mon Sep 17 00:00:00 2001 From: Matthew Nestor Date: Sat, 13 Aug 2022 22:34:35 -0400 Subject: [PATCH 2/2] only handle clear_craft if it makes sense to do so --- mods/HUD/craftguide/init.lua | 38 +++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/mods/HUD/craftguide/init.lua b/mods/HUD/craftguide/init.lua index 0621e28..07a4a5d 100644 --- a/mods/HUD/craftguide/init.lua +++ b/mods/HUD/craftguide/init.lua @@ -1351,24 +1351,30 @@ end local old_clear_craft = core.clear_craft core.clear_craft = function(def) - old_clear_craft(def) + local craft_removed = old_clear_craft(def) - if true_str(def) then - def = match(def, "%S*") - recipes_cache[def] = nil - fuel_cache[def] = nil + if craft_removed then + if true_str(def) then + def = match(def, "%S*") + recipes_cache[def] = nil + fuel_cache[def] = nil - elseif is_table(def) then - for item_name, item_recipes in pairs(recipes_cache) do - for recipe_index, recipe in pairs(item_recipes) do - for ingredient_index, ingredient in pairs(recipe.items) do - if (recipe.type == def.type) and (ingredient == def.recipe) then - table.remove(recipes_cache[item_name], recipe_index) - break - end - end - end - end + elseif is_table(def) then + if def.type == "toolrepair" then + return + end + + for item_name, item_recipes in pairs(recipes_cache) do + for recipe_index, recipe in pairs(item_recipes) do + for ingredient_index, ingredient in pairs(recipe.items) do + if (recipe.type == def.type) and (ingredient == def.recipe) then + table.remove(recipes_cache[item_name], recipe_index) + return + end + end + end + end + end end end