YSPilot

StripMine

May 12th, 2013
5,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.81 KB | None | 0 0
  1. local tArgs = { ... }
  2. if #tArgs ~= 2 then
  3.     print( "Usage: stripmine <length> <Amount of Mines>" )
  4.     return
  5. end
  6.  
  7. -- Mine in a quarry pattern until we hit something we can't dig
  8. local length = tonumber( tArgs[1] )
  9. local mines = tonumber( tArgs[2] )
  10. if length < 1 then
  11.     print( "Tunnel length must be positive" )
  12.     return
  13. end
  14.  
  15. if mines < 1 then
  16.     print( "Number of Mines must be positive" )
  17.     return
  18. end
  19.    
  20. local depth = 0
  21. local collected = 0
  22.  
  23. local function collect()
  24.     collected = collected + 1
  25.     if math.fmod(collected, 25) == 0 then
  26.         print( "Mined "..collected.." items." )
  27.     end
  28. end
  29.  
  30. local function tryDig()
  31.     while turtle.detect() do
  32.         if turtle.dig() then
  33.             collect()
  34.             sleep(0.5)
  35.         else
  36.             return false
  37.         end
  38.     end
  39.     return true
  40. end
  41.  
  42. local function tryDigUp()
  43.     while turtle.detectUp() do
  44.         if turtle.digUp() then
  45.             collect()
  46.             sleep(0.5)
  47.         else
  48.             return false
  49.         end
  50.     end
  51.     return true
  52. end
  53.  
  54. local function tryDigDown()
  55.     while turtle.detectDown() do
  56.         if turtle.digDown() then
  57.             collect()
  58.             sleep(0.5)
  59.         else
  60.             return false
  61.         end
  62.     end
  63.     return true
  64. end
  65.  
  66. local function refuel()
  67.     local fuelLevel = turtle.getFuelLevel()
  68.     if fuelLevel == "unlimited" or fuelLevel > 0 then
  69.         return
  70.     end
  71.    
  72.     local function tryRefuel()
  73.         for n=1,16 do
  74.             if turtle.getItemCount(n) > 0 then
  75.                 turtle.select(n)
  76.                 if turtle.refuel(1) then
  77.                     turtle.select(1)
  78.                     return true
  79.                 end
  80.             end
  81.         end
  82.         turtle.select(1)
  83.         return false
  84.     end
  85.    
  86.     if not tryRefuel() then
  87.         print( "Add more fuel to continue." )
  88.         while not tryRefuel() do
  89.             sleep(1)
  90.         end
  91.         print( "Resuming Tunnel." )
  92.     end
  93. end
  94.  
  95. local function tryUp()
  96.     refuel()
  97.     while not turtle.up() do
  98.         if turtle.detectUp() then
  99.             if not tryDigUp() then
  100.                 return false
  101.             end
  102.         elseif turtle.attackUp() then
  103.             collect()
  104.         else
  105.             sleep( 0.5 )
  106.         end
  107.     end
  108.     return true
  109. end
  110.  
  111. local function tryDown()
  112.     refuel()
  113.     while not turtle.down() do
  114.         if turtle.detectDown() then
  115.             if not tryDigDown() then
  116.                 return false
  117.             end
  118.         elseif turtle.attackDown() then
  119.             collect()
  120.         else
  121.             sleep( 0.5 )
  122.         end
  123.     end
  124.     return true
  125. end
  126.  
  127. local function tryForward()
  128.     refuel()
  129.     while not turtle.forward() do
  130.         if turtle.detect() then
  131.             if not tryDig() then
  132.                 return false
  133.             end
  134.         elseif turtle.attack() then
  135.             collect()
  136.         else
  137.             sleep( 0.5 )
  138.         end
  139.     end
  140.     return true
  141. end
  142.  
  143. local lighta = 0
  144.  
  145. local function addLight()
  146.     lighta = (lighta + 1)
  147.     print( fs.combine("Light Amount = ", tostring(lighta)) )
  148. end
  149.  
  150. local function stripm()
  151.     for n=1,length do
  152.         tryDig()--Digs Forward(bottom)
  153.         tryUp() --Goes Up
  154.         tryDig()--Digs Forward(top)
  155.         tryDown()
  156.         addLight()
  157.         if lighta == 8 then
  158.             tryUp()
  159.             tryDigUp()
  160.             turtle.select(1)
  161.                 if turtle.getItemCount(1) <= 1 then
  162.                     print( "Out of Tourches" )
  163.                 else
  164.                 turtle.placeUp()
  165.                 end
  166.             tryDown()
  167.             lighta = 0
  168.             print( "Torch Placed, Light Reset." )
  169.         end
  170.    
  171.         if n<length then
  172.             tryDig()
  173.             if not tryForward() then
  174.                 print( "Aborting Tunnel." )
  175.                 break
  176.             end
  177.         else
  178.             print( "Tunnel complete." )
  179.         end
  180.  
  181.     end
  182.     print( "Returning" )
  183.     shell.run("go", "back", tostring(length - 1))
  184.     print( "Tunnel complete." )
  185. end
  186.  
  187. local function stripv2()
  188.     for n=1,length do
  189.         tryDig()--Digs Forward(bottom)
  190.         tryDigUp()
  191.         addLight()
  192.         if lighta == 8 then
  193.             tryUp()
  194.             tryDigUp()
  195.             turtle.select(1)
  196.                 if turtle.getItemCount(1) <= 1 then
  197.                     print( "Out of Tourches" )
  198.                 else
  199.                 turtle.placeUp()
  200.                 end
  201.             tryDown()
  202.             lighta = 0
  203.             print( "Torch Placed, Light Reset." )
  204.         end
  205.    
  206.         if n<length then
  207.             tryDig()
  208.             if not tryForward() then
  209.                 print( "Aborting Tunnel." )
  210.                 break
  211.             end
  212.         else
  213.             print( "Tunnel complete." )
  214.         end
  215.  
  216.     end
  217.     print( "Returning" )
  218.     shell.run("go", "back", tostring(length - 1))
  219.     print( "Tunnel complete." )
  220. end
  221.  
  222. local function nextmine()
  223.     turtle.turnLeft()
  224.     turtle.forward()
  225.     turtle.forward()
  226.     turtle.turnRight()
  227. end
  228.  
  229. local function layChest()
  230.     turtle.digDown()
  231.     turtle.select(2)
  232.     turtle.placeDown()
  233.     --Deposits in chest
  234.         turtle.select(3)
  235.         turtle.dropDown()
  236.         turtle.select(4)
  237.         turtle.dropDown()
  238.         turtle.select(5)
  239.         turtle.dropDown()
  240.         turtle.select(6)
  241.         turtle.dropDown()
  242.         turtle.select(7)
  243.         turtle.dropDown()
  244.         turtle.select(8)
  245.         turtle.dropDown()
  246.         turtle.select(9)
  247.         turtle.dropDown()
  248.         turtle.select(10)
  249.         turtle.dropDown()
  250.         turtle.select(11)
  251.         turtle.dropDown()
  252.         turtle.select(12)
  253.         turtle.dropDown()
  254.         turtle.select(13)
  255.         turtle.dropDown()
  256.         turtle.select(14)
  257.         turtle.dropDown()
  258.         turtle.select(15)
  259.         turtle.dropDown()
  260.         turtle.select(16)
  261.         turtle.dropDown()
  262. end
  263.  
  264. print( "Strip Mining..." )
  265. for n=1,mines do
  266. stripv2()
  267. layChest()
  268. nextmine()
  269. --shell.run("nextmine")
  270. end
  271. print( "Strip Mine complete." )
  272. print( "Mined "..collected.." items total." )
  273.  
  274. --310926
Advertisement
Add Comment
Please, Sign In to add comment