Advertisement
Guest User

autoMine

a guest
May 25th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.32 KB | None | 0 0
  1. --Automatic mining program that has turtles dig a 2x3 spur shaft to the left off of a main shaft until inventory is full. Turtle then exits the spur shaft until it hits the wall of the main shaft, heads towards a resupply chest, then empties its contents into a dump chest before heading back through the main shaft to start a new spur.
  2.  
  3. --TODO
  4. --make it so turtles stop at each spur twice to mine
  5.  
  6. --allow turtles to mine veins of ores
  7.  
  8. --switch main from 2Wx6H to 1Wx2H
  9.  
  10. --make function to check for torches in slot 16 and display error message if not
  11.  
  12.  
  13.  
  14. --digs forward and repeats in case of gravel
  15. function gravel()
  16.     while turtle.detect() do
  17.         turtle.dig()
  18.     end
  19. end
  20.  
  21. --digs up and repeats in case of gravel
  22. function gravelUp()
  23.     local i = 0
  24.     while i < 10 do
  25.         turtle.digUp()
  26.         i = i + 1
  27.     end
  28. end
  29.  
  30. --places a torch 2 blocks high on the Right
  31. function placeTorch()
  32.     turtle.select(16)
  33.     turtle.placeUp()
  34. end
  35.  
  36. --looks for fuel if low and refuels
  37. function getFuel()
  38.     if turtle.getFuelLevel() < 90 then
  39.         local i = 1
  40.         while i < 16 do
  41.             turtle.select(i)
  42.             turtle.refuel()
  43.             i = i + 1
  44.         end
  45.     end
  46. print("refueled")
  47. end
  48.  
  49. --digs a 1Wx2H tunnel
  50. function spur()
  51.     gravel()
  52.     turtle.forward()
  53.     gravelUp()
  54. end
  55.  
  56. --digs a 2 wide by 3 tall tunnel
  57. function standard()
  58.     gravel()
  59.     turtle.forward()
  60.     turtle.turnLeft()
  61.     gravel()
  62.     gravelUp()
  63.     turtle.up()
  64.     gravel()
  65.     gravelUp()
  66.     turtle.up()
  67.     gravel()
  68.     turtle.down()
  69.     turtle.down()
  70.     gravel()
  71.     turtle.turnRight()
  72. print ("standard")
  73. end
  74.  
  75. --drops all items in a given slot
  76. function dropStack()
  77.     local s = 0
  78.     while s < 64 do
  79.         turtle.drop()
  80.         s = s + 1
  81.     end
  82. end
  83.  
  84. --function to drop all items except slot in 16
  85. function dropEverything()
  86.     local t = 1
  87.     while t < 16 do
  88.         turtle.select(t)
  89.         dropStack()
  90.         t = t + 1
  91.     end
  92. print("everything dropped")
  93. end
  94.  
  95. --turtle checks amount less 64 of torches it has and takes the remainder from supply chest
  96. function reSupply()
  97.     local supply = 0
  98.     supply = 64 - turtle.getItemCount(16)
  99.     turtle.suck(supply)
  100. print(turtle.getItemCount(16))
  101. print("torches left")
  102. end
  103.  
  104. -- returns the turtle back to base
  105. function returnToBase()
  106. print("returning to base")
  107.     -- variable to allow turtle to travel back to original location
  108.     local path = 0
  109.     turtle.turnLeft()
  110.     turtle.turnLeft()
  111. -- exits spur shaft
  112.     repeat
  113.         turtle.forward()
  114.     until turtle.detect()
  115.     turtle.turnRight()
  116. -- heads down main shaft to supply/dump chest. supply on bottom, dump on top
  117.     repeat
  118.         turtle.forward()
  119.         path = path + 1
  120.     until turtle.detect()
  121.     reSupply()
  122.     turtle.up()
  123.     dropEverything()
  124.     turtle.down()
  125.     turtle.turnRight()
  126.     turtle.turnRight()
  127. --heads back down main shaft
  128.     while path > 0 do
  129.         turtle.forward()
  130.         path = path - 1
  131.     end
  132. --makes main shaft 2 blocks longer
  133.     local q = 0
  134.     while q < 2 do
  135.         standard()
  136.         q = q + 1
  137.     end
  138.     turtle.turnLeft()
  139. end
  140.  
  141. --checks if inventory is full and if true heads back to base
  142. function checkFull()
  143.     local full = 0
  144.     local g = 1
  145.     while g < 16 do
  146.         if turtle.getItemCount(g) > 0 then
  147.             full = full + 1
  148.    print(full)
  149.    print("full")
  150.    end
  151.   g = g + 1
  152.     end
  153.     if full <= 15 then
  154.         returnToBase()
  155.     end
  156. end
  157.  
  158. --main
  159. getFuel()
  160. while turtle.getFuelLevel() > 15 do
  161.     local i = 0
  162.     while i < 5 do
  163.   print("i should dig")
  164.     spur()
  165.         i = i + 1
  166.     end
  167.     getFuel()
  168.     placeTorch()
  169.     checkFull()
  170. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement