Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Fuel Check API --------------------------------------------------------------------------------------------------------------------
- -- API to check a turtles fuel level and refuel itself
- -- This API contains one function: refuel()
- -- The refuel function takes has one parameter named fuelMargin.
- -- The user can input a margin for fuel in units of moves. This margin is compared against the current fuel level of the turtle.
- -- If the fuel margin (number of moves) is less than the fuel level of the turtle,
- -- or no fuel margin is provided, the turtle will attempt to refuel itself
- -- If the turtle finds combustable items in its inventory it will refuel with them, checking all inventory slots for combustable items.
- -- After refueling, if the turtle's fuel level is still below the fuel margin (if provided), a message will be printed with fuel information
- function refuel(fuelMargin)
- local isFueled = true
- if (fuelMargin and turtle.getFuelLevel() < fuelMargin or fuelMargin == nil) then
- isFueled = false
- for i = 1, 16 do
- turtle.select(i)
- local is_fuel = turtle.refuel(0)
- if is_fuel then
- turtle.refuel(64)
- end
- end
- local fuelLevel = turtle.getFuelLevel()
- if (fuelMargin and fuelLevel < fuelMargin ) then
- print("Fuel is still too low\nFuel Margin: " .. fuelMargin .. "\nFuel Level: " .. fuelLevel .. "\nFuel Needed: " .. fuelMargin-fuelLevel)
- return isFueled
- end
- end
- end
Add Comment
Please, Sign In to add comment