feat(inferium-harvester): add config.fertilizedBoost

This commit is contained in:
Guillaume ARM 2024-05-22 01:07:01 +02:00
parent a29f8ac5cb
commit 467378f0c9
2 changed files with 54 additions and 4 deletions

View File

@ -1,4 +1,5 @@
return { return {
fertilizedBoost = false,
length = 8, length = 8,
firstCropZ = 2 firstCropZ = 2
} }

View File

@ -3,14 +3,17 @@ 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 = "2.5.1" local VERSION = "2.6.0"
local INFERIUM_SERVER = 'inferium.com' local INFERIUM_SERVER = 'inferium.com'
local IDLE_TIME = 2 local IDLE_TIME = 2
local WAIT_ITEM_IDLE_TIME = 5 local WAIT_ITEM_IDLE_TIME = 5
local NETWORK_TIMEOUT = 4 local NETWORK_TIMEOUT = 4
local MIN_FUEL_NEEDED = (100 + config.firstCropZ + config.length) * 2 local MIN_FUEL_NEEDED = (100 + config.firstCropZ + config.length) * 2
local MAX_FERTILIZED_ESSENCE = 32
local MIN_FREE_SLOTS_BEFORE_COMPACT = 4 local MIN_FREE_SLOTS_BEFORE_COMPACT = 4
local FERTILIZED_ESSENCE = 'mysticalagriculture:fertilized_essence'
-- a table with the list of current crops -- a table with the list of current crops
local localPlan = nil local localPlan = nil
@ -195,7 +198,17 @@ local function compactIfNeeded()
end end
end end
local function applyFertilizedEssenceIfAny()
if turtleUtils.selectItemByName(FERTILIZED_ESSENCE) then
while turtle.placeDown() do end
end
end
local function harvestDown(index) local function harvestDown(index)
if config.fertilizedBoost then
applyFertilizedEssenceIfAny()
end
local cropName = turtleUtils.waitForMatureCrop(turtle.inspectDown, IDLE_TIME) local cropName = turtleUtils.waitForMatureCrop(turtle.inspectDown, IDLE_TIME)
local seedName = getSeedNameFromCropName(cropName) local seedName = getSeedNameFromCropName(cropName)
@ -230,6 +243,8 @@ local function forward()
end end
local function harvestProcedure() local function harvestProcedure()
goToHarvestPoint()
term.write('> harvest on ' .. tostring(config.length) .. ' blocks ') term.write('> harvest on ' .. tostring(config.length) .. ' blocks ')
local nbHarvested = 0 local nbHarvested = 0
for i=1, config.length, 1 do for i=1, config.length, 1 do
@ -256,6 +271,8 @@ local function harvestProcedure()
forward() forward()
end end
end end
goBackToHome()
end end
local function retrieveLocalPlan() local function retrieveLocalPlan()
@ -357,7 +374,7 @@ local function removeSeeds(seeds)
end end
local function retrieveSeeds(seeds) local function retrieveSeeds(seeds)
print('> retrieve seeds from inventory') print('> retrieve seeds from storage')
local seedRetrieved = false local seedRetrieved = false
local seedsCount = getIndexedCount(seeds) local seedsCount = getIndexedCount(seeds)
@ -389,6 +406,35 @@ local function retrieveSeeds(seeds)
return seedRetrieved return seedRetrieved
end end
local function retrieveFertilizedEssences()
local storageInventory = turtleUtils.waitForInventory('bottom', WAIT_ITEM_IDLE_TIME)
local bufferInventory = turtleUtils.waitForInventory('front', WAIT_ITEM_IDLE_TIME)
local slot = getItemSlot(storageInventory, FERTILIZED_ESSENCE)
if slot then
local inventoryCount = getCountItem(storageInventory, FERTILIZED_ESSENCE)
local realCount = math.min(MAX_FERTILIZED_ESSENCE, inventoryCount)
print('> retrieve ' .. tostring(realCount) .. ' fertilized essences from storage')
local pushOk = storageInventory.pushItems(peripheral.getName(bufferInventory), slot, realCount)
if not pushOk then
error('retrieveFertilizedEssences error: cannot pushItems from storage to buffer')
end
local suckOk = turtle.suck()
if not suckOk then
error('retrieveFertilizedEssences error: cannot suck items from buffer')
end
return true
end
return false
end
local function replantSeeds() local function replantSeeds()
goToHarvestPoint() goToHarvestPoint()
@ -488,9 +534,12 @@ local function main()
replantProcedure() replantProcedure()
goToHarvestPoint() if config.fertilizedBoost then
print('> fertilized boost enabled')
retrieveFertilizedEssences()
end
harvestProcedure() harvestProcedure()
goBackToHome()
cycleNumber = cycleNumber + 1 cycleNumber = cycleNumber + 1
end end