fix(inferium-harvester): replant only when needed
This commit is contained in:
parent
cc1d083aa7
commit
cdad0204ba
@ -2,7 +2,7 @@ local utils = require('libs/utils')
|
|||||||
local turtleUtils = require('libs/turtle-utils')
|
local turtleUtils = require('libs/turtle-utils')
|
||||||
local config = require('config/harvesting')
|
local config = require('config/harvesting')
|
||||||
|
|
||||||
local VERSION = "1.0.0"
|
local VERSION = "1.0.1"
|
||||||
local IDLE_TIME = 2
|
local IDLE_TIME = 2
|
||||||
local WAIT_ITEM_IDLE_TIME = 5
|
local WAIT_ITEM_IDLE_TIME = 5
|
||||||
local MIN_FUEL_NEEDED = (100 + config.firstCropZ + config.length) * 2
|
local MIN_FUEL_NEEDED = (100 + config.firstCropZ + config.length) * 2
|
||||||
@ -337,6 +337,7 @@ local function removeSeeds(seeds)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function retrieveSeeds(seeds)
|
local function retrieveSeeds(seeds)
|
||||||
|
local seedRetrieved = false
|
||||||
local seedsCount = getIndexedCount(seeds)
|
local seedsCount = getIndexedCount(seeds)
|
||||||
|
|
||||||
local storageInventory = turtleUtils.waitForInventory('bottom', WAIT_ITEM_IDLE_TIME)
|
local storageInventory = turtleUtils.waitForInventory('bottom', WAIT_ITEM_IDLE_TIME)
|
||||||
@ -345,7 +346,7 @@ local function retrieveSeeds(seeds)
|
|||||||
for seedName, count in pairs(seedsCount) do
|
for seedName, count in pairs(seedsCount) do
|
||||||
local slot = getItemSlot(storageInventory, seedName)
|
local slot = getItemSlot(storageInventory, seedName)
|
||||||
|
|
||||||
if slot then
|
if slot and count > 0 then
|
||||||
local inventoryCount = getCountItem(storageInventory, seedName)
|
local inventoryCount = getCountItem(storageInventory, seedName)
|
||||||
local realCount = math.min(count, inventoryCount)
|
local realCount = math.min(count, inventoryCount)
|
||||||
local pushOk = storageInventory.pushItems(peripheral.getName(bufferInventory), slot, realCount)
|
local pushOk = storageInventory.pushItems(peripheral.getName(bufferInventory), slot, realCount)
|
||||||
@ -359,8 +360,12 @@ local function retrieveSeeds(seeds)
|
|||||||
if not suckOk then
|
if not suckOk then
|
||||||
error('retrieveSeeds error: cannot suck items from buffer')
|
error('retrieveSeeds error: cannot suck items from buffer')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
seedRetrieved = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return seedRetrieved
|
||||||
end
|
end
|
||||||
|
|
||||||
local function replantSeeds()
|
local function replantSeeds()
|
||||||
@ -418,8 +423,9 @@ local function replantProcedure()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if utils.sizeof(seedsToPlant) > 0 then
|
if utils.sizeof(seedsToPlant) > 0 then
|
||||||
retrieveSeeds(seedsToPlant)
|
if retrieveSeeds(seedsToPlant) then
|
||||||
replantSeeds()
|
replantSeeds()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- reset the local plan (it will be re-updated during the harvest procedure)
|
-- reset the local plan (it will be re-updated during the harvest procedure)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user