Gaimo

Mining

Sep 25th, 2018 (edited)
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | None | 0 0
  1. -- mining <distancia>
  2.  
  3.  
  4. local arguments = {...}
  5. local current_fuel = turtle.getFuelLevel()
  6. local necessary_fuel = 4*arguments[1]
  7.  
  8. local total_torches = 0
  9. local count_tourch = 0
  10. local put_tourch = 5
  11.  
  12.  
  13.  
  14. -- Anti bug
  15. if #arguments ~= 1 then print("mining <distancia>") return end
  16. if tonumber(arguments[1]) < 1 then print("Digite um valor válido.") return end
  17.  
  18. if current_fuel < necessary_fuel then
  19.     turtle.refuel(necessary_fuel)
  20.     if current_fuel < necessary_fuel then
  21.         print("Preciso de "..(necessary_fuel-current_fuel).." combustíveis para iniciar.")
  22.         return
  23.     end
  24. end
  25.  
  26. for i=1, 16 do
  27.     turtle.select(i)
  28.    
  29.     local item = turtle.getItemDetail(i, true)
  30.  
  31.     if item ~= nil then
  32.         if item.name == "minecraft:torch" then
  33.             total_torches = total_torches + item.count
  34.         end
  35.     end
  36. end
  37.  
  38. if tonumber(string.format("%.0f", tostring(arguments[1]/put_tourch))) > total_torches then
  39.     print("Eu preciso de "..tonumber(string.format("%.0f", tostring(arguments[1]/put_tourch))) - total_torches.." tochas para começar.")
  40.     return
  41. end
  42.  
  43. print("Combustivel atual: "..turtle.getFuelLevel())
  44. print("Necessario: "..necessary_fuel)
  45. print("Iniciando...")
  46.  
  47. -- Main loop
  48. for i=1, arguments[1] do
  49.  
  50.     if turtle.detect() then
  51.         turtle.dig("right")
  52.     end
  53.     turtle.forward()
  54.  
  55.     if turtle.detectDown() then
  56.         turtle.digDown("right")
  57.     end
  58.     turtle.down()
  59.  
  60.     if turtle.detectDown() then
  61.         turtle.suckDown()
  62.     else
  63.         for i=1, 16 do
  64.             turtle.select(i)
  65.            
  66.             local item = turtle.getItemDetail(i, true)
  67.  
  68.             if item ~= nil then
  69.                 if item.name == "minecraft:cobblestone" then
  70.                     turtle.placeDown()
  71.                     break
  72.                 end
  73.             end
  74.         end
  75.     end
  76.     turtle.up()
  77.  
  78.     if count_tourch == put_tourch then
  79.  
  80.         for i=1, 16 do
  81.             turtle.select(i)
  82.            
  83.             local item = turtle.getItemDetail(i, true)
  84.  
  85.             if item ~= nil then
  86.                 if item.name == "minecraft:torch" then
  87.                     turtle.placeDown("minecraft:torch")
  88.                     count_tourch = 0
  89.                     break
  90.                 end
  91.             end
  92.         end
  93.        
  94.     end
  95.     count_tourch = count_tourch + 1
  96. end
  97.  
  98. turtle.turnLeft()
  99. turtle.turnLeft()
  100.  
  101. for i=1, arguments[1] do
  102.     turtle.forward()
  103. end
  104.  
  105. print("Mineração concluida com sucesso.")
Advertisement
Add Comment
Please, Sign In to add comment