SHARE
TWEET

Untitled

a guest Aug 25th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. local tArgs = { ... }
  3. if #tArgs ~= 3 then
  4.   print("Usage: clearArea <width> <length> <height>")
  5.   return
  6. end
  7.  
  8. local length = tonumber(tArgs[1])
  9. local width  = tonumber(tArgs[2])
  10. local height = tonumber(tArgs[3])
  11.  
  12. if(length < 1 or width < 1 or length < 1) then
  13.   printError("Arguments cannot be negative.")
  14.   return
  15. end
  16.  
  17. -- Forward/backwards
  18. local xTraveled = 0
  19. -- left/righ
  20. local yTraveled = 0
  21. -- up/down
  22. local zTraveled = 0
  23.  
  24. local totalToMine = length * width * height
  25. local blocksMined = 0
  26.  
  27. local zDir = 0
  28.  
  29. local function turn()
  30.   if math.fmod(yTraveled, 2) == 0
  31.     turtle.turnRight()
  32.   else
  33.     turtle.turnLeft()
  34.   end
  35. end
  36.  
  37. local function digZ()
  38.   if(zDir == 1)
  39.     if turtle.detectUp() then
  40.       turtle.digUp()
  41.     end
  42.     turtle.up()
  43.   else
  44.     if turtle.detectDown() then
  45.       turtle.digDown()
  46.     end
  47.     turtle.down()
  48.   end
  49. end
  50.    
  51. local function dig()
  52.   while(blocksMined < totalToMine)
  53.     while(xTraveled < length)
  54.       while(zTraveled < height)
  55.         digZ()
  56.         blocksMined = blocksMined + 1
  57.         zTraveled = zTraveled + 1
  58.       end
  59.       zTraveled = 0
  60.       zDir = -zDir
  61.       if turtle.detect() then
  62.         turtle.dig()
  63.         blocksMined = blocksMined + 1
  64.       end
  65.       turtle.forward()
  66.       xTraveled = xTraveled + 1
  67.     end
  68.     xTraveled = 0
  69.     turn()
  70.     if turtle.detect() then
  71.       turtle.dig()
  72.     end
  73.     turtle.forward()
  74.     turn()
  75.     yTraveled = yTraveled + 1
  76.     blocksMined = blocksMined + 1
  77.   end
  78. end
  79.  
  80. dig()
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top