Advertisement
Samotage820

cc turtle excavator v2

Jul 30th, 2021 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. args = { ... }
  2. if #args ~= 3 then
  3.     print("Usage: quarry <length> <width> <depth>")
  4.     return
  5. end
  6. x = tonumber(args[1])
  7. y = tonumber(args[2])
  8. z = tonumber(args[3])
  9.  
  10. function dig(n)
  11.     for i=1,n do
  12.         invCheck()
  13.         turtle.dig()
  14.         turtle.forward()
  15.         turtle.digUp()
  16.     end
  17. end
  18.  
  19. function digPlane(x,y)
  20.     for i=1,y do
  21.         dig(x-1)
  22.         if i==y then
  23.             if y%2==0 then
  24.                 turtle.turnLeft()
  25.             else
  26.                 turtle.turnLeft()
  27.                 turtle.turnLeft()
  28.                 dig(x)
  29.             end
  30.         elseif i%2==0 then
  31.             turtle.turnRight()
  32.             dig(1)
  33.             turtle.turnRight()
  34.         else
  35.             turtle.turnLeft()
  36.             dig(1)
  37.             turtle.turnLeft()
  38.         end
  39.     end
  40. end
  41.  
  42. function digVolume(x,y,z)
  43.     for i=1,math.ceil(z/2) do
  44.         if fuelCheck(x+y+z) then
  45.             for i=1,2 do
  46.                 if turtle.detectDown() then
  47.                     if not turtle.digDown() then
  48.                         break
  49.                     end
  50.                 end
  51.                 turtle.down()
  52.             end
  53.             digPlane(x,y)
  54.         end
  55.     end
  56. end
  57.  
  58. function invCheck()
  59.     if turtle.getItemDetail(14) ~= nil then
  60.         turtle.select(16)
  61.         turtle.placeUp()
  62.         for i=2,15 do
  63.             turtle.select(i)
  64.             turtle.dropUp()
  65.         end
  66.         turtle.select(1)
  67.     end
  68. end
  69.  
  70. function fuelCheck(threshold)
  71.     fuel = turtle.getFuelLevel()
  72.     print("Current fuel: ", fuel)
  73.     if fuel <= threshold then
  74.         return turtle.refuel()
  75.     end
  76.     return true
  77. end
  78.  
  79. digVolume(x,y,z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement