Advertisement
theluksabm

Untitled

Apr 6th, 2020
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1.  
  2. local prefix = "[Carlos 0.1a] "
  3.  
  4.  
  5. -- Funcao printf
  6. local function printf(...) print(string.format(...)) end
  7.  
  8. -- Funcao combustivel
  9. local function combustivel()
  10.     local restante = turtle.getFuelLevel() -- Combustivel restante
  11.     local suficiente = false
  12.  
  13.     while true do
  14.         if restante == 0 then
  15.             suficiente = false
  16.             printf("%s Sem combustivel restante, tentando reabastecer.", prefix)
  17.             for i = 1, 16 do
  18.                 turtle.select(i)
  19.                 if turtle.refuel(0) then
  20.                     local halfStack = math.ceil(turtle.getItemCount(i)/2)
  21.                     turtle.refuel(halfStack)
  22.                     break
  23.                 end
  24.             end
  25.         else
  26.             printf("%s Combustivel restante: %s", prefix, restante)
  27.             suficiente = true
  28.             break
  29.         end
  30.  
  31.     return suficiente
  32.  
  33. end
  34.  
  35. local function minerar()
  36.     local possivel = combustivel()
  37.     if possivel then
  38.         turtle.dig()
  39.         turtle.forward()
  40.     else
  41.         printf("%s Sem combustivel.", prefix)
  42.     end
  43.    
  44. end
  45.  
  46. minerar()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement