Refactor autoCompost function to improve dropper capacity checks and item management

This commit is contained in:
MayaTheShy
2026-03-15 23:35:18 -04:00
parent b1c8c261ec
commit ce33c8108f

View File

@@ -1832,19 +1832,24 @@ local function autoCompost()
local dropper = peripheral.wrap(COMPOST_DROPPER)
if not dropper then return didWork end
-- Check how much space the dropper has
-- Check how much item capacity the dropper has (slots * 64 - current items)
local dropperContents = dropper.list()
local dropperUsed = 0
local dropperUsedSlots = 0
local dropperUsedItems = 0
if dropperContents then
for _ in pairs(dropperContents) do dropperUsed = dropperUsed + 1 end
for _, item in pairs(dropperContents) do
dropperUsedSlots = dropperUsedSlots + 1
dropperUsedItems = dropperUsedItems + item.count
end
end
local dropperSize = dropper.size()
local dropperFree = dropperSize - dropperUsed
local dropperFreeSlots = dropperSize - dropperUsedSlots
local dropperFreeItems = (dropperSize * 64) - dropperUsedItems
if dropperFree <= 0 then return didWork end
if dropperFreeItems <= 0 then return didWork end
for _, itemName in ipairs(COMPOSTABLE) do
if dropperFree <= 0 then break end
if dropperFreeItems <= 0 then break end
if catalogue[itemName] then
-- Count total in storage
local totalInStorage = 0
@@ -1854,7 +1859,7 @@ local function autoCompost()
local available = totalInStorage - COMPOST_RESERVE
if available > 0 then
local toFeed = math.min(available, dropperFree, 64)
local toFeed = math.min(available, dropperFreeItems)
local fed = 0
for _, source in ipairs(catalogue[itemName]) do
local chest = peripheral.wrap(source.chest)
@@ -1876,7 +1881,7 @@ local function autoCompost()
end
if fed >= toFeed then break end
end
dropperFree = dropperFree - fed
dropperFreeItems = dropperFreeItems - fed
end
end
end