This commit is contained in:
Laurie Fisher 2025-06-27 14:59:50 +01:00
parent 85703b41e3
commit 92a55f15c9
Signed by: PinkEyedOrphan
GPG Key ID: 7F827B68147AEE76

View File

@ -1,10 +1,31 @@
local M = {}
-- Helper: retry turtle action up to N times
local logger = require("libs.logger")
-- Minimum fuel required to proceed with one movement
local MIN_FUEL = 1 -- you can raise this if you want a safety margin
-- Ensure the turtle has fuel
local function checkFuel()
local fuel = turtle.getFuelLevel()
if fuel == "unlimited" then return true end -- creative mode
if fuel == nil or fuel < MIN_FUEL then
logger.log("Not enough fuel! Current level: " .. tostring(fuel))
return false
end
return true
end
-- Helper: retry an action with fuel check
local function try(actionFn, times)
times = times or 5
for i = 1, times do
if actionFn() then return true end
if not checkFuel() then
logger.log("Waiting for fuel...")
sleep(2)
elseif actionFn() then
return true
end
sleep(0.5)
end
return false