NekoLogi

miner.lua

Jan 30th, 2022 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.89 KB | None | 0 0
  1. function Done()
  2.     print("Finished mining!")
  3. end
  4.  
  5. function TurnBack()
  6.     print("Turning back and going up...")
  7.     turtle.turnRight()
  8.     turtle.turnRight()
  9.     if turtle.detectUp() then
  10.         turtle.digUp()
  11.     end
  12.     while not turtle.up() do
  13.         turtle.digUp()
  14.     end
  15. end
  16.  
  17. function DigLine(lineLength,lineHeight,layers)
  18.     while CheckStorageFull() do
  19.         DropItems()
  20.     end
  21.     print("Digging layer...")
  22.     for e=1,lineHeight do
  23.         for i=1,lineLength do
  24.             while turtle.detect() do
  25.                 turtle.dig()
  26.             end
  27.             while not turtle.forward() do
  28.                 turtle.dig()
  29.             end
  30.         end
  31.         TurnBack()
  32.     end
  33. end
  34.  
  35. function ResetHeight(height)
  36.     print("Resetting height...")
  37.     for i=1,height do
  38.         turtle.down()
  39.     end
  40. end
  41.  
  42. function NextLine()
  43.     print("Preparing for next layer...")
  44.     turtle.turnLeft()
  45.     if turtle.detect() then
  46.         turtle.dig()
  47.     end
  48.     while not turtle.forward() do
  49.         turtle.dig()
  50.     end
  51.     turtle.turnRight()
  52. end
  53.  
  54. function CheckStorageFull()
  55.     for i=2,16 do
  56.         if turtle.getItemCount(i) > 0 then
  57.             return true
  58.         end
  59.         return false
  60.     end
  61. end
  62.  
  63. function DropItems()
  64.     for i=2,16 do
  65.         turtle.select(i)
  66.         turtle.dropDown()
  67.     end
  68. end
  69.  
  70. function Start()
  71.     print("Miner started.")
  72.     local area = RequestInput()
  73.     for i=1,area[3] do
  74.         DigLine(area[1],area[2], area[3])
  75.         ResetHeight(area[2])
  76.         NextLine()
  77.     end
  78.     Done()
  79. end
  80.  
  81. function RequestInput()
  82.     io.write("Enter length:")
  83.     local length = io.read()
  84.     io.write("Enter height:")
  85.     local height = io.read()
  86.     io.write("Enter how many rows should be mined:")
  87.     local layers = io.read()
  88.  
  89.     local area = {tonumber(length),tonumber(height),tonumber(layers)}
  90.  
  91.     return area
  92. end
  93.  
  94. Start()
Add Comment
Please, Sign In to add comment