Refactor autoSmelt function to prioritize food items in candidate list and improve sorting logic
This commit is contained in:
@@ -1371,7 +1371,8 @@ local function autoSmelt()
|
|||||||
-- 4) Load smeltable items into empty input slot
|
-- 4) Load smeltable items into empty input slot
|
||||||
inputItem = contents[SLOT_INPUT]
|
inputItem = contents[SLOT_INPUT]
|
||||||
if not inputItem then
|
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
|
for itemName, recipe in pairs(SMELTABLE) do
|
||||||
-- Check if this furnace type is compatible
|
-- Check if this furnace type is compatible
|
||||||
local compatible = false
|
local compatible = false
|
||||||
@@ -1381,9 +1382,27 @@ local function autoSmelt()
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if compatible and not disabledRecipes[itemName] and catalogue[itemName] then
|
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
|
local totalInStorage = 0
|
||||||
for _, src in ipairs(catalogue[itemName]) do
|
for _, src in ipairs(catalogue[itemName]) do
|
||||||
totalInStorage = totalInStorage + src.total
|
totalInStorage = totalInStorage + src.total
|
||||||
@@ -1391,9 +1410,7 @@ local function autoSmelt()
|
|||||||
|
|
||||||
-- Only smelt the excess beyond SMELT_RESERVE
|
-- Only smelt the excess beyond SMELT_RESERVE
|
||||||
local available = totalInStorage - SMELT_RESERVE
|
local available = totalInStorage - SMELT_RESERVE
|
||||||
if available <= 0 then
|
if available > 0 then
|
||||||
-- Skip: need to keep reserve
|
|
||||||
else
|
|
||||||
local loaded = false
|
local loaded = false
|
||||||
local remaining = math.min(available, 64)
|
local remaining = math.min(available, 64)
|
||||||
for _, source in ipairs(catalogue[itemName]) do
|
for _, source in ipairs(catalogue[itemName]) do
|
||||||
@@ -1420,7 +1437,6 @@ local function autoSmelt()
|
|||||||
end
|
end
|
||||||
if loaded or remaining < math.min(available, 64) then break end
|
if loaded or remaining < math.min(available, 64) then break end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user