Advertisement
asweigart

fuelup

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