test
This commit is contained in:
parent
11b83e3c36
commit
394af21e87
@ -9,7 +9,14 @@ function M.getStatus()
|
|||||||
return currentStatus
|
return currentStatus
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.setStatus(value)
|
||||||
|
currentStatus = value
|
||||||
|
end
|
||||||
|
|
||||||
function M.run()
|
function M.run()
|
||||||
|
-- Register the status setter for turtleutils to call
|
||||||
|
tutil.setStatusCallback(M.setStatus)
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
currentStatus = "moving backward"
|
currentStatus = "moving backward"
|
||||||
logger.log("Started moving backward")
|
logger.log("Started moving backward")
|
||||||
|
|||||||
@ -2,6 +2,13 @@ local M = {}
|
|||||||
|
|
||||||
local logger = require("libs.logger")
|
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
|
-- Minimum fuel required to proceed with one movement
|
||||||
local MIN_FUEL = 1 -- you can raise this if you want a safety margin
|
local MIN_FUEL = 1 -- you can raise this if you want a safety margin
|
||||||
|
|
||||||
@ -29,7 +36,7 @@ local function refuelFromInventory(minRequired)
|
|||||||
return gained
|
return gained
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ✅ Ensure fuel before doing anything
|
-- Ensure fuel before doing anything
|
||||||
local function refuelIfNeeded()
|
local function refuelIfNeeded()
|
||||||
local fuel = turtle.getFuelLevel()
|
local fuel = turtle.getFuelLevel()
|
||||||
if fuel == "unlimited" then return true end
|
if fuel == "unlimited" then return true end
|
||||||
@ -40,15 +47,20 @@ local function refuelIfNeeded()
|
|||||||
fuel = turtle.getFuelLevel()
|
fuel = turtle.getFuelLevel()
|
||||||
end
|
end
|
||||||
|
|
||||||
if fuel < MIN_FUEL then
|
while fuel < MIN_FUEL do
|
||||||
logger.log("Not enough fuel. Waiting...")
|
if statusCallback then statusCallback("out_of_fuel") end
|
||||||
return false
|
logger.log("No fuel. Waiting for fuel...")
|
||||||
|
sleep(5)
|
||||||
|
|
||||||
|
-- Try to refuel again
|
||||||
|
local added = refuelFromInventory(MIN_FUEL)
|
||||||
|
fuel = turtle.getFuelLevel()
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 🚶 Retry a movement or action with fuel awareness
|
-- Retry a movement or action with fuel awareness
|
||||||
local function try(actionFn, times, name)
|
local function try(actionFn, times, name)
|
||||||
times = times or 5
|
times = times or 5
|
||||||
for i = 1, times do
|
for i = 1, times do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user