test
This commit is contained in:
parent
85703b41e3
commit
92a55f15c9
@ -1,10 +1,31 @@
|
|||||||
local M = {}
|
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)
|
local function try(actionFn, times)
|
||||||
times = times or 5
|
times = times or 5
|
||||||
for i = 1, times do
|
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)
|
sleep(0.5)
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user