Advertisement
theluksabm

Untitled

Apr 6th, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 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.                     break
  24.                 end
  25.             end
  26.         else
  27.             printf("%s Combustivel restante: %s", prefix, restante)
  28.             suficiente = true
  29.             break
  30.         end
  31.     end
  32.     return suficiente
  33.  
  34. end
  35.  
  36. -- Funcao minerar
  37. local function minerar(a)
  38.     local possivel = combustivel()
  39.  
  40.     while possivel do
  41.         if possivel then
  42.             turtle.dig()
  43.             turtle.forward()
  44.             possivel = combustivel()
  45.         else
  46.             printf("%s Sem combustivel.", prefix)
  47.         end
  48.     end
  49.  
  50. end
  51.  
  52. minerar()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement