Advertisement
theluksabm

Untitled

Apr 7th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1.  
  2. local prefix = "[Carlos 1.0a] "
  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("%sSem 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("%sCombustivel 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, b, c)
  41.     local possivel = combustivel()
  42.  
  43.  
  44.     while possivel do
  45.  
  46.         for i=1, c do
  47.  
  48.             for i=1, b do
  49.  
  50.                 for i=1 , a-1 do
  51.                     turtle.dig()
  52.                     turtle.forward()
  53.                     possivel = combustivel()
  54.                 end
  55.  
  56.                 if (i % 2) == 1 then
  57.                     turtle.turnRight()
  58.                     turtle.dig()
  59.                     turtle.forward()
  60.                     possivel = combustivel()
  61.                     turtle.turnRight()
  62.                 else
  63.                     turtle.turnLeft()
  64.                     turtle.dig()
  65.                     turtle.forward()
  66.                     possivel = combustivel()
  67.                     turtle.turnLeft()
  68.                 end
  69.             end
  70.  
  71.             if (c % 2) ~= 0 then   
  72.                 turtle.turnRight()
  73.                 turtle.forward()
  74.                 possivel = combustivel()
  75.                 turtle.turnLeft()
  76.                 turtle.digDown()
  77.                 turtle.down()
  78.                 possivel = combustivel()
  79.             end
  80.  
  81.             if (c % 2) == 0 then
  82.                 turtle.digDown()
  83.                 turtle.down()
  84.                 possivel = combustivel()
  85.                 turtle.turnLeft()
  86.  
  87.                 for i=1, b do
  88.                     turtle.dig()
  89.                     turtle.forward()
  90.                 end
  91.                 turtle.turnRight()
  92.             end
  93.  
  94.         end
  95.         break
  96.  
  97.     end
  98. end
  99.  
  100.  
  101. -- Codigo
  102. print(prefix .. "Digite a area para ser minerada: ")
  103. local a = tonumber(read())
  104. local b = tonumber(read())
  105. local c = tonumber(read())
  106.  
  107. minerar(a, b, c)
  108. print(prefix .. "A area foi minerada.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement