This commit is contained in:
Laurie Fisher 2025-06-27 15:08:14 +01:00
parent 11b83e3c36
commit 394af21e87
Signed by: PinkEyedOrphan
GPG Key ID: 7F827B68147AEE76
2 changed files with 24 additions and 5 deletions

View File

@ -9,7 +9,14 @@ function M.getStatus()
return currentStatus
end
function M.setStatus(value)
currentStatus = value
end
function M.run()
-- Register the status setter for turtleutils to call
tutil.setStatusCallback(M.setStatus)
while true do
currentStatus = "moving backward"
logger.log("Started moving backward")

View File

@ -2,6 +2,13 @@ local M = {}
local logger = require("libs.logger")
-- Optional external status setter (set via M.setStatusCallback)
local statusCallback = nil
function M.setStatusCallback(fn)
statusCallback = fn
end
-- Minimum fuel required to proceed with one movement
local MIN_FUEL = 1 -- you can raise this if you want a safety margin
@ -29,7 +36,7 @@ local function refuelFromInventory(minRequired)
return gained
end
-- Ensure fuel before doing anything
-- Ensure fuel before doing anything
local function refuelIfNeeded()
local fuel = turtle.getFuelLevel()
if fuel == "unlimited" then return true end
@ -40,15 +47,20 @@ local function refuelIfNeeded()
fuel = turtle.getFuelLevel()
end
if fuel < MIN_FUEL then
logger.log("Not enough fuel. Waiting...")
return false
while fuel < MIN_FUEL do
if statusCallback then statusCallback("out_of_fuel") end
logger.log("No fuel. Waiting for fuel...")
sleep(5)
-- Try to refuel again
local added = refuelFromInventory(MIN_FUEL)
fuel = turtle.getFuelLevel()
end
return true
end
-- 🚶 Retry a movement or action with fuel awareness
-- Retry a movement or action with fuel awareness
local function try(actionFn, times, name)
times = times or 5
for i = 1, times do