feat(inferium-harvester): do not wait for crops
This commit is contained in:
parent
d16a9b2587
commit
4af7ae8cfe
@ -79,18 +79,19 @@ function isSeed(item)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Inventory utils
|
-- Inventory utils
|
||||||
-- the slot of the item is returned
|
local function getItemSlot(inventory, itemName)
|
||||||
local function waitForItem(inventory, itemName, count, sleepTime)
|
for slot, item in pairs(inventory.list()) do
|
||||||
sleepTime = sleepTime or 5 -- TODO: DEFAULT_IDLE_TIME
|
if item and item.name == itemName then
|
||||||
|
return slot
|
||||||
while true do
|
|
||||||
for slot, item in pairs(inventory.list()) do
|
|
||||||
if item.name == itemName and item.count >= count then
|
|
||||||
return slot
|
|
||||||
end
|
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -338,17 +339,22 @@ local function retrieveSeeds(seeds)
|
|||||||
local bufferInventory = turtleUtils.waitForInventory('front', WAIT_ITEM_IDLE_TIME)
|
local bufferInventory = turtleUtils.waitForInventory('front', WAIT_ITEM_IDLE_TIME)
|
||||||
|
|
||||||
for seedName, count in pairs(seedsCount) do
|
for seedName, count in pairs(seedsCount) do
|
||||||
local slot = waitForItem(storageInventory, seedName, count, WAIT_ITEM_IDLE_TIME)
|
local slot = getItemSlot(storageInventory, seedName)
|
||||||
local pushOk = storageInventory.pushItems(peripheral.getName(bufferInventory), slot, count)
|
|
||||||
|
|
||||||
if not pushOk then
|
if slot then
|
||||||
error('retrieveSeeds error: cannot pushItems from storage to buffer')
|
local inventoryCount = getCountItem(storageInventory, seedName)
|
||||||
end
|
local realCount = math.min(count, inventoryCount)
|
||||||
|
local pushOk = storageInventory.pushItems(peripheral.getName(bufferInventory), slot, realCount)
|
||||||
|
|
||||||
local suckOk = turtle.suck()
|
if not pushOk then
|
||||||
|
error('retrieveSeeds error: cannot pushItems from storage to buffer')
|
||||||
|
end
|
||||||
|
|
||||||
if not suckOk then
|
local suckOk = turtle.suck()
|
||||||
error('retrieveSeeds error: cannot suck items from buffer')
|
|
||||||
|
if not suckOk then
|
||||||
|
error('retrieveSeeds error: cannot suck items from buffer')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user