From b88cbab15d2a80ba0ff34024ab981510e85da398 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sun, 15 Mar 2026 23:04:08 -0400 Subject: [PATCH] Refactor autoSmelt function to prioritize food items in candidate list and improve sorting logic --- inventoryManager.lua | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/inventoryManager.lua b/inventoryManager.lua index a5d7143..5232492 100644 --- a/inventoryManager.lua +++ b/inventoryManager.lua @@ -1371,7 +1371,8 @@ local function autoSmelt() -- 4) Load smeltable items into empty input slot inputItem = contents[SLOT_INPUT] if not inputItem then - -- Find something smeltable in chests that this furnace type can process + -- Build sorted candidate list: food first, then everything else + local candidates = {} for itemName, recipe in pairs(SMELTABLE) do -- Check if this furnace type is compatible local compatible = false @@ -1381,9 +1382,27 @@ local function autoSmelt() break end end - if compatible and not disabledRecipes[itemName] and catalogue[itemName] then - -- Count total of this item across all chests + local isFood = false + for _, ft in ipairs(recipe.furnaces) do + if ft == "minecraft:smoker" then + isFood = true + break + end + end + table.insert(candidates, { name = itemName, recipe = recipe, food = isFood }) + end + end + -- Sort: food first + table.sort(candidates, function(a, b) + if a.food ~= b.food then return a.food end + return a.name < b.name + end) + + -- Try each candidate + for _, cand in ipairs(candidates) do + local itemName = cand.name + -- Count total of this item across all chests local totalInStorage = 0 for _, src in ipairs(catalogue[itemName]) do totalInStorage = totalInStorage + src.total @@ -1391,9 +1410,7 @@ local function autoSmelt() -- Only smelt the excess beyond SMELT_RESERVE local available = totalInStorage - SMELT_RESERVE - if available <= 0 then - -- Skip: need to keep reserve - else + if available > 0 then local loaded = false local remaining = math.min(available, 64) for _, source in ipairs(catalogue[itemName]) do @@ -1420,7 +1437,6 @@ local function autoSmelt() end if loaded or remaining < math.min(available, 64) then break end end - end end end end