From b2d55feb9861a69bda70de160a6d17fa8f1fb4e4 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Wed, 25 Mar 2026 21:53:56 -0400 Subject: [PATCH] feat: add collection hopper emptying function to improve item management --- manager/operations.lua | 65 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/manager/operations.lua b/manager/operations.lua index 83d7301..5002d93 100644 --- a/manager/operations.lua +++ b/manager/operations.lua @@ -765,6 +765,64 @@ function O.autoCompost() return didWork end +------------------------------------------------- +-- Collection hopper emptying (egg spawner, mob farm, etc.) +------------------------------------------------- + +function O.collectHoppers() + if #cfg.COLLECTION_HOPPERS == 0 then return false end + + local didWork = false + local chests = O.getChestsByPriority() + local catalogue = cache.catalogue + + for _, hopperName in ipairs(cfg.COLLECTION_HOPPERS) do + local hopper = O.wrapCached(hopperName) + if hopper then + local contents = hopper.list() + if contents and next(contents) then + for slot, item in pairs(contents) do + local moved = 0 + local triedChests = {} + + -- Prefer chests where item already exists + if catalogue[item.name] then + for _, entry in ipairs(catalogue[item.name]) do + triedChests[entry.chest] = true + local n = hopper.pushItems(entry.chest, slot) + if n and n > 0 then + moved = moved + n + state.adjustCache(item.name, entry.chest, n) + didWork = true + log.info("COLLECT", "%s x%d -> %s (from %s)", item.name, n, entry.chest, hopperName) + end + if moved >= item.count then break end + end + end + + -- Overflow to any chest with space + if moved < item.count then + for _, chest in ipairs(chests) do + if not triedChests[chest] then + local n = hopper.pushItems(chest, slot) + if n and n > 0 then + moved = moved + n + state.adjustCache(item.name, chest, n) + didWork = true + log.info("COLLECT", "%s x%d -> %s (from %s)", item.name, n, chest, hopperName) + end + if moved >= item.count then break end + end + end + end + end + end + end + end + + return didWork +end + ------------------------------------------------- -- Auto-discard excess stock ------------------------------------------------- @@ -788,10 +846,15 @@ function O.discardExcess() local free = (d.size() * 64) - used if free > 0 then table.insert(droppers, { name = dName, handle = d, free = free }) + else + log.debug("DISCARD", "Dropper %s is full, skipping", dName) end end end - if #droppers == 0 then return false end + if #droppers == 0 then + log.debug("DISCARD", "All trash droppers full or offline, cannot discard") + return false + end -- Round-robin index across droppers local dIdx = 1