Refactor autoSmelt function to prioritize food items in candidate list and improve sorting logic

This commit is contained in:
MayaTheShy
2026-03-15 23:04:08 -04:00
parent 66602474b0
commit b88cbab15d

View File

@@ -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