From 0a9294310ad97912c9f78332e6ae422df663ae6c Mon Sep 17 00:00:00 2001 From: Guillaume ARM Date: Wed, 22 May 2024 00:04:17 +0200 Subject: [PATCH] feat(inferium-harvester): better logs on refuel, harvest and remove seeds --- inferium-harvester.lua | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/inferium-harvester.lua b/inferium-harvester.lua index a49bd3f..124ca11 100644 --- a/inferium-harvester.lua +++ b/inferium-harvester.lua @@ -3,7 +3,7 @@ local utils = require('libs/utils') local turtleUtils = require('libs/turtle-utils') local config = require('config/harvesting') -local VERSION = "2.3.0" +local VERSION = "2.5.0" local INFERIUM_SERVER = 'inferium.com' local IDLE_TIME = 2 local WAIT_ITEM_IDLE_TIME = 5 @@ -157,11 +157,19 @@ local function dropAllProcedure() end local function refuelProcedure() - print('> refuel') - local refuelOk, refuelErr = turtleUtils.refuelWithBuffer('bottom', 'front', MIN_FUEL_NEEDED, IDLE_TIME) + local fuelLevel = turtle.getFuelLevel() + print('> fuel: ' .. tostring(fuelLevel)) - if not refuelOk then - error('Cannot refuel the turtle: "' .. refuelErr .. '"') + if fuelLevel < MIN_FUEL_NEEDED then + print('> refuel needed (minimum is ' .. MIN_FUEL_NEEDED .. ')') + + local refuelOk, refuelErr = turtleUtils.refuelWithBuffer('bottom', 'front', MIN_FUEL_NEEDED, IDLE_TIME) + + if not refuelOk then + error('Cannot refuel the turtle: "' .. refuelErr .. '"') + end + + print('> fuel: ' .. tostring(fuelLevel)) end end @@ -222,15 +230,23 @@ local function forward() end local function harvestProcedure() - print('> harvest') - + term.write('> harvest on ' .. tostring(config.length) .. ' blocks') + local nbHarvested = 0 for i=1, config.length, 1 do - harvestDown(i) + if harvestDown(i) then + nbHarvested = nbHarvested + 1 + term.write(' .') + else + term.write(' !') + end if i ~= config.length then forward() end end + term.write('\n') + + print('> ' .. tostring(nbHarvested) .. ' harvested crops') turtle.turnLeft() turtle.turnLeft() @@ -302,7 +318,7 @@ end local function removeSeeds(seeds) goToHarvestPoint() - print('> remove old seeds') + print('> remove ' .. utils.sizeof(seeds) .. ' seed(s)') local stateSeeds = seeds -- warning: do not mutate the data (only the ref) for i=1, config.length, 1 do