asweigart

fuelup

Jul 28th, 2016
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. -- Fueling program
  2. -- By Al Sweigart
  3. -- Consumes all fuel smartly.
  4.  
  5. os.loadAPI('hare')
  6. local consumed, slot
  7. local FUEL_TABLE = {lava_bucket=1000, coal=60, planks=15, log=15}
  8.  
  9. -- check if server is set to unlimited
  10. if turtle.getFuelLimit() == 'unlimited' then
  11. print('Unlimited fuel mode is enabled.')
  12. return
  13. end
  14.  
  15. -- check that the turtle has a label
  16. if os.getComputerLabel() == nil then
  17. print('WARNING: Set a label or else fuel will')
  18. print('be lost when turtle is picked up!')
  19. end
  20.  
  21. print('Fueling...')
  22.  
  23. -- search for each type of fuel
  24. for fuelType, fuelAmount in pairs(FUEL_TABLE) do
  25. while hare.fuelSpace() > fuelAmount and hare.selectItem(fuelType) do
  26. consumed = turtle.refuel(1) -- consume lava
  27. if not consumed then
  28. break -- break if not consumed
  29. end
  30. end
  31. end
  32.  
  33. -- check if fuelgauge program exists
  34. if fs.exists('fuelgauge') then
  35. -- display fuel info nicely
  36. os.loadAPI('fuelgauge')
  37. end
Advertisement
Add Comment
Please, Sign In to add comment