nSun

OffshoreQuarrySetup

Mar 24th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. -- Offshore Quarry Setup
  2. local args = {...}
  3.  
  4. -- Check if there 3 arguments
  5. if #args ~= 1  then
  6.   print("Usage: OffshoreQuarrySetup <L/R>")
  7.   return
  8. end
  9.  
  10. local dir = "L"
  11. dir = args[1]
  12.  
  13. if dir == "l" or dir == "L" then
  14.     dir = "L"
  15. else
  16.     dir = "R"
  17. end
  18.  
  19. local function tryDig()
  20.     while turtle.detect() do
  21.         if turtle.dig() then
  22.             sleep(0.3)
  23.         else
  24.             return false
  25.         end
  26.     end
  27.     return true
  28. end
  29.  
  30. local function refuel()
  31.     local fuelLevel = turtle.getFuelLevel()
  32.     if fuelLevel == "unlimited" or fuelLevel > 0 then
  33.         return
  34.     end
  35.    
  36.     local function tryRefuel()
  37.         for n=1,16 do
  38.             if turtle.getItemCount(n) > 0 then
  39.                 turtle.select(n)
  40.                 if turtle.refuel(1) then
  41.                     turtle.select(1)
  42.                     return true
  43.                 end
  44.             end
  45.         end
  46.         turtle.select(1)
  47.         return false
  48.     end
  49.    
  50.     if not tryRefuel() then
  51.         print( "Add more fuel to continue." )
  52.         while not tryRefuel() do
  53.             sleep(1)
  54.         end
  55.         print( "Resuming Quarry Setup." )
  56.     end
  57. end
  58.  
  59.  
  60. local function tryForward()
  61.     refuel()
  62.     while not turtle.forward() do
  63.         if turtle.detect() then
  64.             if not tryDig() then
  65.                 return false
  66.             end
  67.         elseif turtle.attack() then
  68.             -- collect()
  69.         else
  70.             sleep( 0.3 )
  71.         end
  72.     end
  73.     return true
  74. end
  75.  
  76. -- dig
  77.  
  78. for i=1,2 do
  79.     for n=1,17 do
  80.         turtle.placeDown()
  81.        
  82.         if n<17 then
  83.             tryDig()
  84.             if not tryForward() then
  85.                 print( "Aborting Setup." )
  86.                 break
  87.             end
  88.         else
  89.             print( "Segment complete." )
  90.         end
  91.  
  92.     end
  93.     if dir == "L" then
  94.         turtle.turnLeft()
  95.     else
  96.         turtle.turnRight()
  97.     end
  98.     for n=1,17 do
  99.         turtle.placeDown()
  100.        
  101.         if n<17 then
  102.             tryDig()
  103.             if not tryForward() then
  104.                 print( "Aborting Setup." )
  105.                 break
  106.             end
  107.         else
  108.             print( "Segment complete." )
  109.         end
  110.  
  111.     end
  112.     if dir == "L" then
  113.         turtle.turnLeft()
  114.     else
  115.         turtle.turnRight()
  116.     end
  117. end
  118.  
  119.  
  120. print( "Chunk delimited." )
Advertisement
Add Comment
Please, Sign In to add comment