Advertisement
theluksabm

Untitled

Apr 7th, 2020
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.08 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.  
  39. -- Funcao minerar
  40. local function minerar(a)
  41.     local possivel = combustivel()
  42.  
  43.  
  44.     while possivel do
  45.  
  46.         local i = 1
  47.  
  48.         repeat
  49.             turtle.dig()
  50.             turtle.forward()
  51.             possivel = combustivel()
  52.             i = i + 1
  53.         until i == a
  54.  
  55.     end
  56.  
  57. end
  58.  
  59. local a = io.read("*n")
  60. minerar(a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement