From 467378f0c9c5751f258248f9b7dcc6f86aabb65e Mon Sep 17 00:00:00 2001 From: Guillaume ARM Date: Wed, 22 May 2024 01:07:01 +0200 Subject: [PATCH] feat(inferium-harvester): add config.fertilizedBoost --- config/harvesting.lua | 1 + inferium-harvester.lua | 57 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/config/harvesting.lua b/config/harvesting.lua index 8af9e2b..598ea2b 100644 --- a/config/harvesting.lua +++ b/config/harvesting.lua @@ -1,4 +1,5 @@ return { + fertilizedBoost = false, length = 8, firstCropZ = 2 } diff --git a/inferium-harvester.lua b/inferium-harvester.lua index a734c8d..c05b7ac 100644 --- a/inferium-harvester.lua +++ b/inferium-harvester.lua @@ -3,14 +3,17 @@ local utils = require('libs/utils') local turtleUtils = require('libs/turtle-utils') local config = require('config/harvesting') -local VERSION = "2.5.1" +local VERSION = "2.6.0" local INFERIUM_SERVER = 'inferium.com' local IDLE_TIME = 2 local WAIT_ITEM_IDLE_TIME = 5 local NETWORK_TIMEOUT = 4 local MIN_FUEL_NEEDED = (100 + config.firstCropZ + config.length) * 2 +local MAX_FERTILIZED_ESSENCE = 32 local MIN_FREE_SLOTS_BEFORE_COMPACT = 4 +local FERTILIZED_ESSENCE = 'mysticalagriculture:fertilized_essence' + -- a table with the list of current crops local localPlan = nil @@ -195,7 +198,17 @@ local function compactIfNeeded() end end +local function applyFertilizedEssenceIfAny() + if turtleUtils.selectItemByName(FERTILIZED_ESSENCE) then + while turtle.placeDown() do end + end +end + local function harvestDown(index) + if config.fertilizedBoost then + applyFertilizedEssenceIfAny() + end + local cropName = turtleUtils.waitForMatureCrop(turtle.inspectDown, IDLE_TIME) local seedName = getSeedNameFromCropName(cropName) @@ -230,6 +243,8 @@ local function forward() end local function harvestProcedure() + goToHarvestPoint() + term.write('> harvest on ' .. tostring(config.length) .. ' blocks ') local nbHarvested = 0 for i=1, config.length, 1 do @@ -256,6 +271,8 @@ local function harvestProcedure() forward() end end + + goBackToHome() end local function retrieveLocalPlan() @@ -357,7 +374,7 @@ local function removeSeeds(seeds) end local function retrieveSeeds(seeds) - print('> retrieve seeds from inventory') + print('> retrieve seeds from storage') local seedRetrieved = false local seedsCount = getIndexedCount(seeds) @@ -389,6 +406,35 @@ local function retrieveSeeds(seeds) return seedRetrieved 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() goToHarvestPoint() @@ -488,9 +534,12 @@ local function main() replantProcedure() - goToHarvestPoint() + if config.fertilizedBoost then + print('> fertilized boost enabled') + retrieveFertilizedEssences() + end + harvestProcedure() - goBackToHome() cycleNumber = cycleNumber + 1 end