feat(inferium-harvester): do not wait for crops

This commit is contained in:
Guillaume ARM 2024-05-21 17:56:27 +02:00
parent d16a9b2587
commit 4af7ae8cfe

View File

@ -79,18 +79,19 @@ function isSeed(item)
end
-- Inventory utils
-- the slot of the item is returned
local function waitForItem(inventory, itemName, count, sleepTime)
sleepTime = sleepTime or 5 -- TODO: DEFAULT_IDLE_TIME
while true do
local function getItemSlot(inventory, itemName)
for slot, item in pairs(inventory.list()) do
if item.name == itemName and item.count >= count then
if item and item.name == itemName then
return slot
end
end
end
os.sleep(IDLE_TIME)
local function getCountItem(inventory, itemName)
for _, item in pairs(inventory.list()) do
if item and item.name == itemName then
return item.count
end
end
end
@ -338,8 +339,12 @@ local function retrieveSeeds(seeds)
local bufferInventory = turtleUtils.waitForInventory('front', WAIT_ITEM_IDLE_TIME)
for seedName, count in pairs(seedsCount) do
local slot = waitForItem(storageInventory, seedName, count, WAIT_ITEM_IDLE_TIME)
local pushOk = storageInventory.pushItems(peripheral.getName(bufferInventory), slot, count)
local slot = getItemSlot(storageInventory, seedName)
if slot then
local inventoryCount = getCountItem(storageInventory, seedName)
local realCount = math.min(count, inventoryCount)
local pushOk = storageInventory.pushItems(peripheral.getName(bufferInventory), slot, realCount)
if not pushOk then
error('retrieveSeeds error: cannot pushItems from storage to buffer')
@ -352,6 +357,7 @@ local function retrieveSeeds(seeds)
end
end
end
end
local function replantSeeds()
goToHarvestPoint()