From 929768a12a1539cdd2ac30481fff699f638e4092 Mon Sep 17 00:00:00 2001 From: Luke aka SwissalpS Date: Thu, 15 Jun 2023 03:52:57 +0200 Subject: [PATCH] rebuild cache whenever recipe inv changes no need to check if still current, this only happens when user is interacting and can only be better to do so. Otherwise we would have to check groups etc. again just to check, so might as well reset cache. --- autocrafter.lua | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/autocrafter.lua b/autocrafter.lua index 4eb5187..3ba6414 100644 --- a/autocrafter.lua +++ b/autocrafter.lua @@ -249,30 +249,16 @@ end local function after_recipe_change(pos, inventory) local hash = minetest.hash_node_position(pos) local meta = minetest.get_meta(pos) + autocrafterCache[hash] = nil -- if we emptied the grid, there's no point in keeping it running or cached if inventory:is_empty("recipe") then minetest.get_node_timer(pos):stop() - autocrafterCache[hash] = nil meta:set_string("infotext", S("unconfigured Autocrafter")) inventory:set_stack("output", 1, "") return end local recipe = inventory:get_list("recipe") - local craft = autocrafterCache[hash] - - if craft then - -- check if it changed - local cached_recipe = craft.recipe - for i = 1, 9 do - if recipe[i]:get_name() ~= cached_recipe[i]:get_name() then - autocrafterCache[hash] = nil -- invalidate recipe - craft = nil - break - end - end - end - - craft = craft or get_craft(pos, inventory, hash) + local craft = get_craft(pos, inventory, hash) local output_item = craft.output.item local description, name = get_item_info(output_item) meta:set_string("infotext", S("'@1' Autocrafter (@2)", description, name))