Advertisement
theluksabm

Untitled

Apr 6th, 2020
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 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.  
  9. -- Funcao combustivel
  10. local function combustivel()
  11.     local restante = turtle.getFuelLevel() -- Combustivel restante
  12.     local suficiente = false
  13.  
  14.     while true do
  15.         if restante == 0 then
  16.             suficiente = false
  17.             printf("%s Sem combustivel restante, tentando reabastecer.", prefix)
  18.             for i = 1, 16 do
  19.                 turtle.select(i)
  20.                 if turtle.refuel(0) then
  21.                     local halfStack = math.ceil(turtle.getItemCount(i)/2)
  22.                     turtle.refuel(halfStack)
  23.                     restante = turtle.getFuelLevel()
  24.                     suficiente = true
  25.                     break
  26.                 end
  27.             end
  28.         else
  29.             printf("%s Combustivel restante: %s", prefix, restante)
  30.             suficiente = true
  31.             break
  32.         end
  33.     end
  34.     return suficiente
  35.  
  36. end
  37.  
  38. -- Funcao minerar
  39. local function minerar(a)
  40.     local possivel = combustivel()
  41.  
  42.     while possivel do
  43.         if possivel then
  44.             turtle.dig()
  45.             turtle.forward()
  46.             possivel = combustivel()
  47.         else
  48.             printf("%s Sem combustivel.", prefix)
  49.         end
  50.     end
  51.  
  52. end
  53.  
  54. minerar()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement