Advertisement
Guest User

fuel

a guest
Jun 26th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1. local fuel = 0
  2.  
  3. function setFuelLevel(min)
  4.   fuel = min
  5. end
  6. function getMinFuel()
  7.   return fuel
  8. end
  9.  
  10. function isFull()
  11.   for i = 1,16 do
  12.     if turtle.getItemCount(i) == 0 then
  13.       return false
  14.     end
  15.   end
  16.   return true
  17. end
  18.  
  19.  
  20. function refuel()
  21.   local f = turtle.getFuelLevel()
  22.  
  23.   if f < fuel then
  24.     local count = 1
  25.     turtle.select(count)
  26.    
  27.     repeat
  28.       f = turtle.getFuelLevel()
  29.      
  30.       if not turtle.refuel(1) then
  31.         count = count + 1
  32.         if count > 16 then return -1 end
  33.         turtle.select(count)
  34.         --turtle.select(
  35.         --(turtle.getSelectedSlot() < 16 and turtle.getSelectedSlot()+1)
  36.         --or 1)
  37.       end
  38.      
  39.     until f >= fuel
  40.     return 1 -- fueling success
  41.   end
  42.    
  43.   return 0 --no need to refuel
  44. end
  45.  
  46. function ret() --stands for return,
  47.                --as in return to base
  48.   if isFull() or refuel() == -1 then
  49.     return true
  50.   end
  51.   return false
  52. end
  53.  
  54.  
  55. function idle()
  56.   if isFull() then
  57.     print("Inventory is full, press q to end")
  58.     local t = read()
  59.     if t == "q" or t == "Q" then return -1 end
  60.     idle()
  61.   end
  62.   if refuel() == - 1 then
  63.     print("Need more fuel")
  64.     print(turtle.getFuelLevel())
  65.     print("Press q to end")
  66.     local t = read()
  67.     if t == "q" or t == "Q" then return -1 end
  68.     idle()
  69.   end
  70.   return 1
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement