Enhance auto-smelting function to check for incompatible items in input slot and remove them

This commit is contained in:
MayaTheShy
2026-03-15 22:37:12 -04:00
parent 34e308161f
commit 2ef7af16a5

View File

@@ -772,7 +772,37 @@ local function autoSmelt()
-- Re-read after output pull
contents = furnace.list()
-- 2) Refuel if fuel slot is empty or low
-- 2) Check for incompatible items in input slot and remove them
local furnaceType = peripheral.getType(fname)
local inputItem = contents[SLOT_INPUT]
if inputItem then
local recipe = SMELTABLE[inputItem.name]
local validHere = false
if recipe then
for _, ft in ipairs(recipe.furnaces) do
if ft == furnaceType then
validHere = true
break
end
end
end
if not validHere then
-- This item doesn't belong in this furnace type — pull it out
for _, chest in ipairs(chests) do
local n = furnace.pushItems(chest, SLOT_INPUT)
if n and n > 0 then
print(string.format("[SMELT] Removed incompatible %s x%d from %s -> %s",
inputItem.name, n, fname, chest))
didWork = true
break
end
end
-- Re-read after removal
contents = furnace.list()
end
end
-- 3) Refuel if fuel slot is empty or low
local fuelItem = contents[SLOT_FUEL]
local needFuel = not fuelItem or fuelItem.count < 8
@@ -803,9 +833,8 @@ local function autoSmelt()
end
end
-- 3) Load smeltable items into empty input slot
local inputItem = contents[SLOT_INPUT]
local furnaceType = peripheral.getType(fname)
-- 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
for itemName, recipe in pairs(SMELTABLE) do