deltreey

mine

Nov 28th, 2016
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. os.loadAPI('/fuel')
  2.  
  3. local args = { ... }
  4. if #args < 2 or #args > 3 then
  5.   print( "Usage: quarry <toTheRight> <toTheFront>[ <toTheDown>]" )
  6.   error()
  7. end
  8.  
  9. function checkFuel()
  10.     while (turtle.getFuelLevel() < 100) do
  11.         if (fuel.canRefuel()) then
  12.             fuel.fuelUp()
  13.         else
  14.             return false
  15.         end
  16.     end
  17.     return true
  18. end
  19.  
  20. function fullInventory()
  21.     local full = true
  22.     local current = 1
  23.     while (current < 16) do
  24.         if (turtle.getItemCount(current) == 0) then
  25.             full = false
  26.         end
  27.         current = current + 1
  28.     end
  29.     return full
  30. end
  31.  
  32. function dropEverything()
  33.     local current = 1
  34.     while (current < 16) do
  35.         turtle.dropDown()
  36.         current = current + 1
  37.     end
  38. end
  39.  
  40. function digLength()
  41.     local forward = 0
  42.     while (forward < tonumber(args[2])) do
  43.         if (not checkFuel()) then
  44.             return false
  45.         end
  46.         if (turtle.detect()) then
  47.             turtle.dig()
  48.         end
  49.         turtle.forward()
  50.         forward = forward + 1
  51.         if (fullInventory()) then
  52.             dropEverything()
  53.         end
  54.     end
  55.     return true
  56. end
  57.  
  58. local canRefuel = true
  59. local depth = 0
  60. while (true) do
  61.     if (not digLength()) then
  62.         return
  63.     end
  64.     local right = 0
  65.     while (right < tonumber(args[1])) do
  66.         turtle.turnRight()
  67.         if (turtle.detect()) then
  68.             turtle.dig()
  69.         end
  70.         turtle.forward()
  71.         turtle.turnRight()
  72.         if (not digLength()) then
  73.             return
  74.         end
  75.         turtle.turnLeft()
  76.         if (turtle.detect()) then
  77.             turtle.dig()
  78.         end
  79.         turtle.forward()
  80.         turtle.turnLeft()
  81.         if (not digLength()) then
  82.             return
  83.         end
  84.         right = right + 2
  85.     end
  86.  
  87.     if (#args > 2) then
  88.         if (depth >= tonumber(args[3])) then
  89.             print('Mining Complete')
  90.             return
  91.         end
  92.     end
  93.  
  94.     turtle.turnRight()
  95.     turtle.turnRight()
  96.     if (turtle.detectDown()) then
  97.         if (not turtle.digDown()) then
  98.             print ('Reached the bottom')
  99.             return
  100.         end
  101.     end
  102.     turtle.down()
  103.     depth = depth + 1
  104.  
  105.     print('Dug ' .. depth .. ' layers')
  106. end
Advertisement
Add Comment
Please, Sign In to add comment