Advertisement
Himeki

MultiMine

Feb 7th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.15 KB | None | 0 0
  1. --Program to mine out several layers. Definable length, width, and depth.
  2.  
  3. -- config
  4. local width = 0
  5. local length = 0
  6. local depth = 0
  7. local linecount = 0 -- number times completed a length
  8. local layercount = 0 -- number of times completed a layer
  9. local lblocks = 0 -- total blocks in layer
  10. local cblocks = 0 -- total blocks moved
  11. local dblocks = 0 -- blocks dug so far minus air
  12. local tblocks = 0 -- total blocks in area
  13. local mblocks = 0 -- current line progress
  14. local goneleft = false -- has turtle gone left yet
  15.  
  16. --functions start
  17.  
  18. --clear
  19. function clear()
  20.     term.clear()
  21.     term.setCursorPos(1,1)
  22. end
  23.  
  24. --dig line
  25. local function line()
  26.     mblocks = 0
  27.     while mblocks < length do
  28.         if turtle.dig() == true then
  29.             dblocks = dblocks+1
  30.         end
  31.         while turtle.forward() ~= true do
  32.             os.sleep(0.5)
  33.         end
  34.         mblocks = mblocks+1
  35.         cblocks = cblocks+1
  36.     end
  37.     print("dug " .. dblocks .. "/" .. lblocks .. "(" .. tblocks .. ")" .. " blocks, turtle.")
  38.     linecount = linecount+1
  39.     print("Line function complete")
  40. end
  41.  
  42. -- turn left and dig a line
  43. local function lineleft()
  44.     turtle.turnLeft()
  45.     if turtle.dig() == true then
  46.         dblocks = dblocks+1
  47.     end
  48.     while turtle.forward() ~= true do
  49.         os.sleep(0.5)
  50.     end
  51.     cblocks = cblocks+1
  52.     turtle.turnLeft()
  53.     line()
  54. end
  55.  
  56. -- turn right and dig a line
  57. local function lineright()
  58.     turtle.turnRight()
  59.     if turtle.dig() == true then
  60.         dblocks = dblocks+1
  61.     end
  62.     while turtle.forward() ~= true do
  63.         os.sleep(0.5)
  64.     end
  65.     cblocks = cblocks+1
  66.     turtle.turnRight()
  67.     line()
  68. end
  69.  
  70. -- does it go left or right?
  71. local function alternate()
  72.     if goneleft == true then
  73.         lineright()
  74.         goneleft = false
  75.     else
  76.         lineleft()
  77.         goneleft = true
  78.     end
  79. end
  80.  
  81. -- go down
  82. local function linestart()
  83.     if turtle.digDown() == true then
  84.         dblocks = dblocks+1
  85.     end
  86.     turtle.down()
  87.     cblocks = cblocks+1
  88.     print("Line function time")
  89.     line()
  90. end
  91.  
  92. -- do 180 and dig down to start another layer
  93. local function nextlayer()
  94.     print("Layer complete, starting next layer, turtle.")
  95.     print("Cleared " .. lblocks .. "/" .. tblocks)
  96.     turtle.turnLeft()
  97.     turtle.turnLeft()
  98.     linecount = 0
  99.     print("Linestart function time")
  100.     linestart()
  101. end    
  102.  
  103. --begin code
  104. clear()
  105. print("Place me above block at bottom right of area, turtle.")
  106. write("Enter Width: ")
  107. width = tonumber(read())
  108. write("Enter Length: ")
  109. length = tonumber(read()-1)
  110. write("Enter Depth: ")
  111. depth = tonumber(read())
  112. tblocks = ((length+1)*(width)*(depth))
  113. lblocks = ((length+1)*(width))
  114.  
  115. linestart()
  116.  
  117. while (cblocks < tblocks) do
  118.     while linecount < width do
  119.         print("alternate function time")
  120.         alternate()
  121.     end
  122.     layercount = layercount+1
  123.     if layercount < depth then
  124.         print("nextlayer function time")
  125.         nextlayer()
  126.         print("nextlayer function complete, loop to alternate")
  127.     end
  128.     print("returning to loop cblocks")
  129. end
  130. print("Done. Mined " .. dblocks .. " out of " .. tblocks .. " blocks total, turtle.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement