z3ntu

MiningProgram

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