Advertisement
Himeki

Layer miner

Jan 29th, 2013
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. -- config
  2. local width = 0
  3. local length = 0
  4. local linecount = 0
  5. local dblocks = 0 -- blocks dug so far minus air
  6. local tblocks = 0 -- total blocks in area
  7. local mblocks = 0 -- current line progress
  8. local goneleft = false -- has turtle gone left yet
  9.  
  10. --functions start
  11.  
  12. --clear
  13. function clear()
  14.     term.clear()
  15.     term.setCursorPos(1,1)
  16. end
  17.  
  18. --dig line
  19. local function line()
  20.     mblocks = 0
  21.     while mblocks < length do
  22.         if turtle.dig() == true then
  23.             dblocks = dblocks+1
  24.         end
  25.         while turtle.forward() ~= true do
  26.             os.sleep(0.5)
  27.         end
  28.         mblocks = mblocks+1
  29.     end
  30.     print("dug " .. dblocks .. "/" .. tblocks .. " blocks.")
  31.     linecount = linecount+1
  32. end
  33.  
  34. -- turn left and dig a line
  35. local function lineleft()
  36.     turtle.turnLeft()
  37.     if turtle.dig() == true then
  38.         dblocks = dblocks+1
  39.     end
  40.     while turtle.forward() ~= true do
  41.         os.sleep(0.5)
  42.     end
  43.     turtle.turnLeft()
  44.     line()
  45. end
  46.  
  47. -- turn right and dig a line
  48. local function lineright()
  49.     turtle.turnRight()
  50.     if turtle.dig() == true then
  51.         dblocks = dblocks+1
  52.     end
  53.     while turtle.forward() ~= true do
  54.         os.sleep(0.5)
  55.     end
  56.     turtle.turnRight()
  57.     line()
  58. end
  59.  
  60. --begin code
  61. clear()
  62. print("Place turtle above block at bottom right of area.")
  63. write("Enter Width: ")
  64. width = tonumber(read())
  65. write("Enter Length: ")
  66. length = tonumber(read()-1)
  67. tblocks = ((length+1)*(width))
  68.  
  69. if turtle.digDown() == true then
  70.     dblocks = dblocks+1
  71. end
  72.  
  73. turtle.down()
  74. line()
  75.  
  76. while linecount < width do
  77.     if goneleft == true then
  78.         lineright()
  79.         goneleft = false
  80.     else
  81.         lineleft()
  82.         goneleft = true
  83.     end
  84. end
  85. print("Done. Mined " .. dblocks .. " out of " .. tblocks .. " blocks total.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement