feat: add collection hopper emptying function to improve item management
This commit is contained in:
@@ -765,6 +765,64 @@ function O.autoCompost()
|
|||||||
return didWork
|
return didWork
|
||||||
end
|
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
|
-- Auto-discard excess stock
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
@@ -788,10 +846,15 @@ function O.discardExcess()
|
|||||||
local free = (d.size() * 64) - used
|
local free = (d.size() * 64) - used
|
||||||
if free > 0 then
|
if free > 0 then
|
||||||
table.insert(droppers, { name = dName, handle = d, free = free })
|
table.insert(droppers, { name = dName, handle = d, free = free })
|
||||||
|
else
|
||||||
|
log.debug("DISCARD", "Dropper %s is full, skipping", dName)
|
||||||
end
|
end
|
||||||
end
|
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
|
-- Round-robin index across droppers
|
||||||
local dIdx = 1
|
local dIdx = 1
|
||||||
|
|||||||
Reference in New Issue
Block a user