LazyNub

ShaftMiner 1.52c

May 6th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.85 KB | None | 0 0
  1. --[[ShaftMiner 1.52c
  2.     As seen in The ComputerCraft Challenge [youtube.com/bwochinski]
  3.  
  4.     Changes made by LazyNub to original
  5.         Trash Cleanup added 5-5-13
  6.         fourth trash choice added 5-5-13
  7.         Changed Trashdump to 15lvl intervals 5-6-13
  8.         Made 1st slot cover material 5-6-13
  9.         Removed cover material slot option 5-6-13
  10.         Changed Trashdump to 30lvl intervals 5-10-13
  11.         Added Inventory Compressor Function every 10 lvls 5-10-13
  12.             (Based on code from ProfessionalProcrastinator http://pastebin.com/YK2tVjRM)
  13.  
  14.         This program will mine in vertical shafts down to bedrock, checking the walls of the shaft.
  15.         Shafts are staggered so the turtle will view every block if the pattern is continued.
  16.         Set "consoleID" to the id of a computer listening on rednet to get remote status messages.
  17.         ** Prep the Turtle before running! **
  18.         Slots 1,2,3,4 are for blocks not to mine (smooth stone, gravel, dirt, cobble)
  19.         Slot 1 is also the block to backfill holes (recommend cobble)
  20.         Slot 16 is for fuel only
  21. ]]--
  22. depth = 0
  23. runs = 0
  24.  
  25. function fuel()
  26.         if turtle.getFuelLevel() <= depth + 10 then
  27.                 if not turtle.getItemCount(16) then
  28.             print("Running out of fuel")
  29.         end
  30.         turtle.select(16)
  31.                 turtle.refuel(1)       
  32.         end
  33. end
  34.  
  35. function isValuable()
  36.         if turtle.detect() == false then
  37.                 return false
  38.         end
  39.         for i=1,4 do
  40.                 turtle.select(i)
  41.                 if turtle.compare() then
  42.                         return false
  43.                 end
  44.         end
  45.         turtle.select(1)
  46.     return true
  47. end
  48.  
  49. function compressInv()
  50.     print ("Compressing")
  51.     for i = 1,15 do
  52.         if turtle.getItemCount(i) > 0 and turtle.getItemCount(i) < 64 then
  53.                 turtle.select(i)
  54.                 for j = i+1,15 do
  55.                     if turtle.compareTo(j) then
  56.                         turtle.select(j)
  57.                         turtle.transferTo(i)
  58.                         turtle.select(i)
  59.                     end
  60.                 end
  61.         end
  62.     end
  63.     for i = 5,15 do
  64.         if turtle.getItemCount(i) > 0 then
  65.                 for j = 5,i do
  66.                     if turtle.getItemCount(j) == 0 then
  67.                         turtle.select(i)
  68.                         turtle.transferTo(j)
  69.                         break
  70.                     end
  71.                 end
  72.         end
  73.     end
  74.     for i = 5,15 do
  75.         turtle.select(16)
  76.         if turtle.compareTo(i) then
  77.             turtle.select(i)
  78.             turtle.transferTo(16)
  79.         end
  80.     end
  81.     print ("Compressed")
  82. end
  83.  
  84. function dumptrash()
  85.     for tr=5,15 do
  86.         turtle.select(tr)
  87.         for i=1,4 do
  88.             if turtle.compareTo(i) then
  89.                 turtle.dropDown()
  90.                 if isWireless then
  91.                             rednet.broadcast("Droped Trash At depth "..depth)
  92.                     end
  93.             end
  94.         end
  95.     end
  96.     for i=1,4 do
  97.         turtle.select(i)
  98.         if turtle.getItemCount(i)>8 then
  99.             turtle.dropDown(turtle.getItemCount(i)-8)
  100.         end
  101.     end
  102.     turtle.select(1)
  103. end
  104.  
  105.  
  106. function checkWalls(dp)
  107.         for j=1,4 do
  108.                 if isValuable() then
  109.                         turtle.dig()
  110.                 end
  111.         turtle.turnRight()
  112.         end
  113. end
  114.  
  115.            
  116. ------ ( Program Start ) ------
  117. term.clear()
  118. term.setCursorPos(1,1)
  119.  
  120. print("Ben's Simple Turtle Miner")
  121. print("-------------------------")
  122. print("  Mods made by LazyNub")
  123. print("-------------------------")
  124.  
  125. term.write("How many runs in to start: ")
  126. runs = read() * 1
  127. print("\n")
  128. term.write("How many runs to mine: ")
  129. runcount = read() * 1
  130. print("\n")
  131.  
  132. runcount = runs + runcount
  133.  
  134. while runs < runcount do
  135.        
  136.         limruns = runs*2
  137.  
  138.         for dee=1,limruns do
  139.                     fuel()
  140.             while not turtle.forward() do
  141.                 turtle.dig()
  142.                 sleep(.8)
  143.             end
  144.        
  145.             while not turtle.forward() do
  146.                 turtle.dig()
  147.                 sleep(.8)
  148.             end
  149.            
  150.             turtle.turnRight()
  151.            
  152.             while not turtle.forward() do
  153.                 turtle.dig()
  154.                 sleep(.8)
  155.             end
  156.            
  157.             turtle.turnLeft()
  158.         end
  159.            
  160.        
  161.         depth = 0
  162.         print("Commencing mining.")
  163.         fuel()
  164.         turtle.digDown()
  165.         for st=1,2 do
  166.                 turtle.down()
  167.                 depth = depth + 1
  168.         print("Current Depth "..depth)
  169.                 turtle.digDown()
  170.     end
  171.        
  172.         -- plug entrance hole
  173.         turtle.select(1)
  174.         turtle.placeUp()
  175.        
  176.         while not turtle.detectDown() do
  177.                 fuel()
  178.                 turtle.down()
  179.                 depth = depth + 1
  180.         print("Current Depth "..depth)
  181.                 if isWireless and depth%10==0 then
  182.                         rednet.broadcast("At depth "..depth)
  183.                 end
  184.         if depth%10==0 then
  185.             compressInv()
  186.         end
  187.         if depth%30==0 then
  188.             dumptrash()
  189.         end
  190.                 checkWalls(depth)
  191.                 turtle.digDown()
  192.         end
  193.        
  194.         for mv=1,6 do
  195.                 fuel()
  196.                 turtle.up()
  197.                 depth = depth - 1
  198.         print("Current Depth "..depth)
  199.         end
  200.        
  201.     -- move forward 2 blocks
  202.     print("Moving to upward shaft")
  203.         for z=1,2 do
  204.                 fuel()
  205.                 while not turtle.forward() do
  206.                         turtle.dig()
  207.                         sleep(.8)
  208.                 end
  209.         end
  210.        
  211.         -- turn right and move one block
  212.         turtle.turnRight()
  213.         fuel()
  214.         while not turtle.forward() do
  215.                 turtle.dig()
  216.                 sleep(.8)
  217.         end
  218.         turtle.turnLeft()
  219.        
  220.         -- go down to bedrock
  221.         turtle.digDown()
  222.         while not turtle.detectDown() do
  223.                 fuel()
  224.         turtle.select(1)
  225.                 turtle.down()
  226.                 depth = depth + 1
  227.                 turtle.digDown()
  228.         print("Current Depth "..depth)
  229.         end
  230.         print("Digging up second shaft")
  231.         for k=depth,3,-1 do
  232.                 checkWalls(k)
  233.                 turtle.digUp()
  234.                 fuel()
  235.         print("Current Depth "..k)
  236.         if k%10==0 then
  237.             compressInv()
  238.         end
  239.         if k%30==0 then
  240.             dumptrash()
  241.         end
  242.                 while not turtle.up() do
  243.                         turtle.digUp()
  244.                         sleep(.5)
  245.                 end
  246.         end
  247.         dumptrash()
  248.     fuel()
  249.         turtle.digUp()
  250.         turtle.up()
  251.         turtle.digUp()
  252.         turtle.up()
  253.        
  254.     -- fill exit hole
  255.         turtle.select(1)
  256.         turtle.placeDown()
  257.        
  258.         limitruns = runs*2 + 1
  259.         runs = runs + 1;
  260.        
  261.         turtle.turnLeft()
  262.         turtle.turnLeft()
  263.  
  264.         for deez=1,limitruns do
  265.                     fuel() 
  266.             turtle.turnRight()
  267.            
  268.             while not turtle.forward() do
  269.                 turtle.dig()
  270.                 sleep(.8)
  271.             end
  272.            
  273.             turtle.turnLeft()
  274.        
  275.             while not turtle.forward() do
  276.                 turtle.dig()
  277.                 sleep(.8)
  278.             end
  279.            
  280.             while not turtle.forward() do
  281.                 turtle.dig()
  282.                 sleep(.8)
  283.             end
  284.         end
  285.        
  286.         for bal=5,15 do
  287.             turtle.select(bal)
  288.             turtle.drop()
  289.         end
  290.        
  291.         turtle.turnRight()
  292.         turtle.turnRight()
  293.            
  294. end
  295.  
  296. print("Cancelled mining.")
Advertisement
Add Comment
Please, Sign In to add comment