local refuel = require("modules.refuel") local inv_utils = require("modules.inv_utils") local DATA_PATH = "/data/sorter_data.txt" local function runDiagnostics() local canStart = true print("Running diagnostics...") print(string.format("Fuel level: %s", turtle.getFuelLevel())) local fuelStorage = peripheral.wrap("front") local hasInStorage = refuel.hasFuelInStorage(fuelStorage) and "yes" or "no" print(string.format("Fuel in storage: %s", hasInStorage)) local dataExists = fs.exists(DATA_PATH) if not dataExists then canStart = false end print(string.format("Data path exists: %s", dataExists and "yes" or "no")) local hasItemsInUnsorted = inv_utils.hasItemsInStorage(peripheral.wrap("top")) if not hasItemsInUnsorted then canStart = false end print(string.format("Items in unsorted storage: %s", hasItemsInUnsorted and "yes" or "no")) local hasItemsInLeftover = inv_utils.hasItemsInStorage(peripheral.wrap("bottom")) if hasItemsInLeftover then canStart = false end print(string.format("Items in leftover storage: %s", hasItemsInLeftover and "yes" or "no")) if canStart then print("Ready to start sorting.") else print("Can not start sorting.") end return canStart end local function run() local result = runDiagnostics() if not result then return nil end write("Start? (y/N) ") local response = read() local firstChar = string.sub(response, 1, 1) if firstChar == "y" or firstChar == "Y" then print("Started sorting.") else print("Aborted.") return nil end end return { run = run }