SHARE
TWEET

Untitled

a guest Jan 11th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. local tArgs = { ... }
  3. if #tArgs ~= 2 then
  4.     print( "Usage: mt <length> <torchlength>" )
  5.     return
  6. end
  7.  
  8. -- Mine in a quarry pattern until we hit something we can't dig
  9. local length = tonumber( tArgs[1] )
  10. local torchl = tonumber( tArgs[2] )
  11. if length < 1 then
  12.     print( "Tunnel length must be positive" )
  13.     return
  14. end
  15. if torchl < 1 then
  16.   print( "Torch length 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. print( "Tunnelling..." )
  144. local TorchCount = 0
  145.  
  146. for n=1,length do
  147. -- tryForward()
  148.  turtle.select(1)
  149.  turtle.placeDown(1)
  150.  turtle.turnRight()
  151.  tryDig()
  152.  turtle.turnLeft()
  153.  turtle.turnLeft()
  154.  tryDig()
  155.  tryUp()
  156.  turtle.turnRight()
  157.  turtle.turnRight()
  158.  tryDig()
  159.  turtle.turnLeft()
  160.  tryDig()
  161.  turtle.turnLeft()
  162.  tryDig()
  163.  tryUp()
  164.  turtle.turnRight()
  165.  turtle.turnRight()
  166.  tryDig()
  167.  turtle.turnLeft()
  168.  tryDig()
  169.  turtle.turnLeft()
  170.  tryDig()
  171.  tryDown()
  172.  tryDown()
  173.  TorchCount = TorchCount + 1
  174.  if TorchCount == torchl then
  175.    turtle.turnLeft()
  176.    turtle.select(2)
  177.    turtle.place(2)
  178.    TorchCount = 0
  179.    turtle.turnRight()  
  180.  end
  181.  turtle.turnRight()
  182.  
  183.  --turnRight()
  184.  --tryDown()
  185.  --tryDown()
  186.  --tryUp()
  187.          
  188.     if n<length then
  189.         tryDig()
  190.         if not tryForward() then
  191.             print( "Aborting Tunnel." )
  192.             break
  193.         end
  194.     else
  195.         print( "Tunnel complete." )
  196.     end
  197.  
  198. end
  199.  
  200. --[[
  201. print( "Returning to start..." )
  202.  
  203. -- Return to where we started
  204. turtle.turnLeft()
  205. turtle.turnLeft()
  206. while depth > 0 do
  207.     if turtle.forward() then
  208.         depth = depth - 1
  209.     else
  210.         turtle.dig()
  211.     end
  212. end
  213. turtle.turnRight()
  214. turtle.turnRight()
  215. ]]
  216.  
  217. print( "Tunnel complete." )
  218. print( "Mined "..collected.." items total." )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top