Wassaa

shaft

Jan 31st, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.20 KB | None | 0 0
  1. --[[
  2.     As seen in The ComputerCraft Challenge [youtube.com/bwochinski]
  3.     This program will mine in vertical shafts down to bedrock, checking the walls of the shaft.
  4.     Shafts are staggered so the turtle will view every block if the pattern is continued.
  5.     Set "consoleID" to the id of a computer listening on rednet to get remote status messages.
  6.     ** Prep the Turtle before running! **
  7.     Slots 1,2,3 are for blocks not to mine (smooth stone, gravel, dirt)
  8.     Slot 15 is the block to backfill holes (recommend cobble)
  9.     Slot 16 is for fuel
  10. ]]--
  11. isWireless = false
  12. consoleID = 1
  13. depth = 0
  14.  
  15. function fuel()
  16.     if turtle.getFuelLevel() <= depth + 10 then
  17.         turtle.select(16)
  18.         turtle.refuel(1)
  19.         if isWireless then rednet.send(consoleID,"Refueled. Fuel level: "..turtle.getFuelLevel()) end
  20.     end
  21. end
  22.  
  23. function isValuable()
  24.     if turtle.detect() == false then
  25.         return false
  26.     end
  27.     for i=1,3 do
  28.         turtle.select(i)
  29.         if turtle.compare() then
  30.             return false
  31.         end
  32.     end
  33.     return true
  34. end
  35.  
  36. function checkWalls(dp)
  37.     for j=1,4 do
  38.         if isValuable() then
  39.             if isWireless then rednet.send(consoleID,"Found ore at depth "..dp) end
  40.             turtle.dig()
  41.         end
  42.         turtle.turnRight()
  43.     end
  44. end
  45.  
  46. ------ ( Program Start ) ------
  47.  
  48. if isWireless == true then
  49.    rednet.open("right")
  50. end
  51.  
  52. term.clear()
  53. term.setCursorPos(1,1)
  54. print("Ben's Simple Turtle Miner")
  55. print("-------------------------")
  56.  
  57. term.write("Go on mining run? (y/n): ")
  58.  
  59. while read() == "y" do
  60.    
  61.     depth = 0
  62.     print("Commencing mining.")
  63.     if isWireless then rednet.send(consoleID,"Commencing mining.") end
  64.    
  65.     fuel()
  66.     turtle.digDown()
  67.     for st=1,2 do
  68.         turtle.down()
  69.         depth = depth + 1
  70.         turtle.digDown()
  71.     end
  72.    
  73.     -- plug entrance hole
  74.     turtle.select(15)
  75.     turtle.placeUp()
  76.    
  77.     while not turtle.detectDown() do
  78.         fuel()
  79.         turtle.down()
  80.         depth = depth + 1
  81.         if isWireless and depth%10==0 then
  82.             rednet.send(consoleID,"At depth "..depth)
  83.         end
  84.         checkWalls(depth)
  85.         turtle.digDown()
  86.     end
  87.    
  88.     if isWireless then rednet.send(consoleID,"Moving to next shaft location...") end
  89.    
  90.     for mv=1,6 do
  91.         fuel()
  92.         turtle.up()
  93.         depth = depth - 1
  94.     end
  95.    
  96.     -- move forward 2 blocks
  97.     for z=1,2 do
  98.         fuel()
  99.         while not turtle.forward() do
  100.             turtle.dig()
  101.             sleep(.8)
  102.         end
  103.     end
  104.    
  105.     -- turn right and move one block
  106.     turtle.turnRight()
  107.     fuel()
  108.     while not turtle.forward() do
  109.         turtle.dig()
  110.         sleep(.8)
  111.     end
  112.     turtle.turnLeft()
  113.    
  114.     -- go down to bedrock
  115.     turtle.digDown()
  116.     while not turtle.detectDown() do
  117.         fuel()
  118.         turtle.down()
  119.         depth = depth + 1
  120.         turtle.digDown()
  121.     end
  122.    
  123.     if isWireless then rednet.send(consoleID,"Returning to surface!") end
  124.    
  125.     for k=depth,3,-1 do
  126.         checkWalls(k)
  127.         turtle.digUp()
  128.         fuel()
  129.         while not turtle.up() do
  130.             turtle.digUp()
  131.             sleep(.5)
  132.         end
  133.         if isWireless and k%10 == 0 then
  134.             rednet.send(consoleID,"At depth "..k)
  135.         end
  136.     end
  137.    
  138.     fuel()
  139.     turtle.digUp()
  140.     turtle.up()
  141.     turtle.digUp()
  142.     turtle.up()
  143.    
  144.     -- fill exit hole
  145.     turtle.select(15)
  146.     turtle.placeDown()
  147.    
  148.     turtle.forward()
  149.     turtle.forward()
  150.     turtle.turnRight()
  151.     turtle.forward()
  152.     turtle.turnLeft()
  153.    
  154.     term.write("Go on mining run? (y/n): ")
  155. end
  156.  
  157. print("Cancelled mining.")
  158.  
  159. if isWireless then rednet.close("right") end
Add Comment
Please, Sign In to add comment