RyuuzakiJulio

Miner01

Jan 22nd, 2013
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.51 KB | None | 0 0
  1. depth = 0
  2.  
  3. function status(msg)
  4.  if isWireless then
  5.   rednet.broadcast(msg)
  6.  end
  7.   term.print(msg)
  8. end
  9.  
  10. function dropLoot(r)
  11.  if r~=nil then
  12.   turtle.turnRight()
  13.   turtle.turnRight()
  14.  end
  15.  
  16.  for i=1,4 do
  17.   turtle.select(i)
  18.   turtle.drop(turtle.getItemCount(i)-1)
  19.  end
  20.  for i=5,14 do
  21.   turtle.select(i)
  22.   turtle.drop(turtle.getItemCount(i))
  23.  end
  24.  
  25.  if r~=nil then
  26.   turtle.turnRight()
  27.   turtle.turnRight()
  28.  end
  29.  
  30.  turtle.select(1)
  31.  
  32. end
  33.  
  34.  
  35. function fuel()
  36.     if turtle.getFuelLevel() <= depth + 10 then
  37.         turtle.select(16)
  38.         turtle.refuel(1)
  39.         status("Refueled. Fuel level: "..turtle.getFuelLevel())
  40.     end
  41. end
  42.  
  43. function isValuable()
  44.     if turtle.detect() == false then
  45.         return false
  46.     end
  47.     for i=1,4 do
  48.         turtle.select(i)
  49.         if turtle.compare() then
  50.             return false
  51.         end
  52.     end
  53.     return true
  54. end
  55.  
  56. function checkWalls(dp)
  57.     for j=1,4 do
  58.         if isValuable() then
  59.             status("Ore at depth "..dp)
  60.             turtle.select(1)
  61.             turtle.dig()
  62.         end
  63.         turtle.turnRight()
  64.     end
  65. end
  66.  
  67. ------ ( Program Start ) ------
  68.  
  69. sSide = nil
  70. if sSide == nil then
  71.        for n,sMonitorSide in ipairs(rs.getSides()) do
  72.             if peripheral.isPresent(sMonitorSide) and peripheral.getType(sMonitorSide) == "modem" then
  73.                sSide = sMonitorSide
  74.                break
  75.             end
  76.        end
  77.     if not sSide then
  78.        print( "No modem attached" )
  79.     end
  80.  
  81.     if sSide ~= nil then
  82.         if rednet.open("right") == true then
  83.         isWireless = true
  84.     end
  85. end
  86.  
  87. end
  88.  
  89.  
  90.  
  91. term.clear()
  92. term.setCursorPos(1,1)
  93. print(os.getComputerLabel().." : "..turtle.getFuelLevel().." | Simple Turtle Miner")
  94. print("-------------------------")
  95. term.write("Start Mining? (y/n): ")
  96.  
  97. while read() == "y" do
  98.    
  99.     depth = 0
  100.     print("Commencing mining.")
  101.     status(os.getComputerLabel().." : Commencing mining.")
  102.    
  103.     fuel()
  104.     turtle.digDown()
  105.     for st=1,2 do
  106.         turtle.down()
  107.         depth = depth + 1
  108.         turtle.digDown()
  109.     end
  110.    
  111.     -- plug entrance hole
  112.     turtle.select(15)
  113.     turtle.placeUp()
  114.    
  115.     while not turtle.detectDown() do
  116.         fuel()
  117.         turtle.down()
  118.         depth = depth + 1
  119.         if depth%5 == 0 then
  120.          status("Depth "..depth.." DN")
  121.       end
  122.         checkWalls(depth)
  123.         turtle.digDown()
  124.     end
  125.    
  126.     status("Moving to next shaft")
  127.    
  128.     for mv=1,6 do
  129.         fuel()
  130.         turtle.up()
  131.         depth = depth - 1
  132.     end
  133.    
  134.     -- move forward 2 blocks
  135.     for z=1,2 do
  136.         fuel()
  137.         while not turtle.forward() do
  138.             turtle.dig()
  139.             sleep(.8)
  140.         end
  141.     end
  142.    
  143.     -- turn right and move one block
  144.     turtle.turnRight()
  145.     fuel()
  146.     while not turtle.forward() do
  147.         turtle.dig()
  148.         sleep(.8)
  149.     end
  150.     turtle.turnLeft()
  151.    
  152.     -- go down to bedrock
  153.     turtle.digDown()
  154.     while not turtle.detectDown() do
  155.         fuel()
  156.         turtle.down()
  157.         depth = depth + 1
  158.         turtle.digDown()
  159.     end
  160.    
  161.     status("Returning to surface!")
  162.    
  163.     for k=depth,3,-1 do
  164.         checkWalls(k)
  165.         turtle.select(1)
  166.         turtle.digUp()
  167.         fuel()
  168.         while not turtle.up() do
  169.             turtle.select(1)
  170.             turtle.digUp()
  171.             sleep(.5)
  172.         end
  173.         if k%5 == 0 then
  174.             status("Depth "..k.." UP")
  175.         end
  176.     end
  177.    
  178.     fuel()
  179.     turtle.select(1)
  180.     turtle.digUp()
  181.     turtle.up()
  182.     turtle.select(1)
  183.     turtle.digUp()
  184.     turtle.up()
  185.    
  186.     -- fill exit hole
  187.     turtle.select(15)
  188.     turtle.placeDown()
  189.     turtle.select(1)
  190.     turtle.dig()
  191.     turtle.forward()
  192.     turtle.select(1)
  193.     turtle.dig()
  194.     turtle.forward()
  195.     turtle.turnRight()
  196.     turtle.select(1)
  197.     turtle.dig()
  198.     turtle.forward()
  199.     turtle.turnLeft()
  200.    
  201.    
  202.     print("Press enter to drop loot")
  203.     r=read()
  204.    
  205.     dropLoot(r)
  206.    
  207.     print("F:"..turtle.getFuelLevel())
  208.     term.write("Mine? (y/n): ")
  209.    
  210. end
  211.  
  212. print("Cancelled mining.")
Advertisement
Add Comment
Please, Sign In to add comment