tterrag1098

Branch 1.3 beta

Jun 18th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local tArgs = {...}
  2. local length = tArgs[1]
  3. local numTunnels = tArgs[2]
  4. local inv = true
  5. local checkTorch = 0
  6. local height = 0
  7. local fullInvNum = 0
  8.  
  9. -- The basic function to move forward and dig
  10. function tunnel()
  11.   -- These used throughout to erase screen
  12.   term.clear()
  13.   term.setCursorPos(1,1)
  14.   print("Mining...")
  15.   for i=1,length do
  16.     fuel()
  17.     turtle.dig()
  18.     -- This loop prevents gravel from screwing it all up
  19.     while turtle.forward() == false do
  20.       turtle.dig()
  21.     end
  22.     turtle.digUp()
  23.     torch()
  24.   end
  25. end
  26.  
  27. -- The function to turn around and go the other direction down the tunnel, also clears side tunnels
  28. function turnAround()
  29.   term.clear()
  30.   term.setCursorPos(1,1)
  31.   print("Turning around...")
  32.   for k = 1,6 do
  33.     fuel()
  34.     turtle.dig()
  35.     while turtle.forward() == false do
  36.       turtle.dig()
  37.     end
  38.     turtle.digUp()
  39.     torch()
  40.   end
  41.  
  42.   checkInv()
  43.  
  44.   while turtle.back() == false do
  45.     turtle.turnRight()
  46.     turtle.turnRight()
  47.     turtle.dig()
  48.     for i = 1,3 do
  49.       turtle.forward()
  50.       turtle.dig()
  51.     end
  52.     turtle.turnRight()
  53.     turtle.turnRight()
  54.     for i = 1,3 do
  55.       turtle.back()  
  56.     end
  57.   end
  58.   turtle.back()
  59.   turtle.back()
  60. end
  61.  
  62. -- Clears the specified item from the inventory, most likely cobble, also stops on full inv
  63. function checkInv()
  64.   term.clear()
  65.   term.setCursorPos(1,1)
  66.   print("Trashing...")
  67.   for y = 2,16 do
  68.     turtle.select(y)
  69.     if turtle.compareTo(1) then
  70.       turtle.drop()
  71.     end
  72.   end
  73.    
  74. function fullInv()
  75.   -- To not spill items everywhere, some credit to link0153 :)
  76.   for i = 1,16 do
  77.     if turtle.getItemCount(i) > 0 then
  78.       fullInvNum = fullInvNum + 1
  79.     end
  80.   end
  81.   if fullInvNum == 16 then
  82.     term.clear()
  83.     term.setCursorPos(1,1)
  84.     print("Inventory full, please clear.")
  85.     sleep(5)
  86.     fullInv()
  87.   end
  88.   fullInvNum = 0
  89.   term.clear()
  90.   term.setCursorPos(1,1)
  91.   print("Mining...")
  92. end
  93.  
  94. -- Checks how long since the last torch, then decides to place one above or not
  95. function torch()
  96.   -- Checks if low on torches
  97.   if turtle.getItemCount(16) < 5 then
  98.     term.clear()
  99.     term.setCursorPos(1,1)
  100.     print("Waiting for torches...place in bottom right.")
  101.     while turtle.getItemCount(16) < 5 do
  102.       sleep(2)
  103.     end
  104.   end
  105.   term.clear()
  106.   term.setCursorPos(1,1)
  107.   print("Mining...")
  108.   if checkTorch == 8 then
  109.     fuel()
  110.     turtle.select(16)
  111.     turtle.up()
  112.     turtle.digUp()
  113.     -- This if and loop will bring the turtle back down from the placed torch
  114.     if turtle.placeUp() or turtle.getItemCount(16) == 0 then
  115.         for i = 0,height do
  116.           fuel()
  117.           turtle.down()
  118.         end
  119.         turtle.select(1)
  120.         checkTorch = 0
  121.         height = 0
  122.     else
  123.         height = height + 1
  124.         torch()
  125.     end
  126.   -- If it's too soon, dont place a torch
  127.   else
  128.     checkTorch = checkTorch + 1
  129.   end
  130. end
  131.  
  132. -- Checks the fuel level, asks for more if necessary
  133. function fuel()
  134.   if turtle.getFuelLevel() < 50 then
  135.     print ("Wating for fuel...place in bottom left.")    
  136.     while turtle.getFuelLevel() < 50 do
  137.       turtle.select(13)
  138.       turtle.refuel()
  139.       sleep(2)
  140.     end
  141.   end
  142.   term.clear()
  143.   term.setCursorPos(1,1)
  144.   print("Mining...")
  145.   turtle.select(1)
  146. end
  147.  
  148. -- This function is a one time startup function, makes sure the turtle has the necessary materials
  149. function begin()
  150.   turtle.select(1)
  151.   -- Checks for trash item
  152.   if turtle.getItemCount(1) == 0 then
  153.     print("Please place an item to trash in the top left.")
  154.     while turtle.getItemCount(1) == 0 do
  155.       sleep(1)
  156.     end
  157.     term.clear()
  158.     term.setCursorPos(1,1)
  159.     begin()
  160.   -- Confirms trashed item
  161.   else
  162.     print("The item in the top left will be trashed...confirm?")
  163.     os.pullEvent("key")
  164.   end
  165.   term.clear()
  166.   term.setCursorPos(1,1)
  167. end
  168.  
  169. -- From here is the main code          
  170. begin()
  171. -- Loops for the specified # of tunnels, one tunnel being up and back
  172. for j = 1,numTunnels do
  173.   tunnel()
  174.   fullInv()
  175.   turtle.turnLeft()
  176.   turnAround()
  177.   fullInv()
  178.   turtle.turnLeft()
  179.   tunnel()
  180.   fullInv()
  181.   turtle.turnRight()
  182.   turnAround()
  183.   fullInv()
  184.   turtle.turnRight()
  185. end
  186. -- Resets the screen and displays a confirmation of finishing
  187. term.clear()
  188. term.setCursorPos(1,1)
  189. print("Done!")
Advertisement
Add Comment
Please, Sign In to add comment