Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Helper function to get the fuel percentage
- local function getFuelPercentage()
- local fuelLevel = turtle.getFuelLevel()
- local fuelLimit = turtle.getFuelLimit()
- if fuelLevel == "unlimited" or fuelLimit == "unlimited" then
- return "Unlimited"
- elseif fuelLimit > 0 then
- return math.floor((fuelLevel / fuelLimit) * 100) .. "%"
- else
- return "N/A"
- end
- end
- -- Function to refuel the turtle
- local function autoRefuel()
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item then
- -- Try to refuel with the item
- turtle.select(slot)
- if turtle.refuel(0) then -- Check if the item is burnable
- print("Refueling with " .. item.name)
- turtle.refuel() -- Perform the refuel
- break -- Stop after refueling
- end
- end
- end
- turtle.select(1) -- Reset to the first slot
- end
- -- Helper function to inspect blocks
- local function inspectBlock(inspectFunc)
- local success, data = inspectFunc()
- if success then
- return data.name or "Unknown Block"
- else
- return "Air/None"
- end
- end
- -- Main loop
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- -- Print fuel info
- print("Turtle Status Test")
- print("------------------")
- print("Fuel Level: " .. (turtle.getFuelLevel() or "N/A"))
- print("Fuel Limit: " .. (turtle.getFuelLimit() or "N/A"))
- print("Fuel Percentage: " .. getFuelPercentage())
- -- Refuel if needed
- if turtle.getFuelLevel() < 100 then -- Refuel if fuel level is below 100
- print("Fuel level low, attempting to refuel...")
- autoRefuel()
- end
- -- Inspect blocks around the turtle
- print("\nBlocks Around Turtle:")
- print("Front: " .. inspectBlock(turtle.inspect))
- print("Above: " .. inspectBlock(turtle.inspectUp))
- print("Below: " .. inspectBlock(turtle.inspectDown))
- -- Wait 5 seconds before refreshing
- sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement