Advertisement
jeriktelorian

ComputerCraft Dig Plane

Sep 2nd, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.78 KB | None | 0 0
  1. function DigHorizontalPlane(width, depth, turnRightFirst, alreadyInPlane)
  2.     rowCount = 1
  3.     nextTurn = 0
  4.    
  5.     if turnRightFirst then
  6.         nextTurn = 1 --  Positive indicates a right turn
  7.     else
  8.         nextTurn = -1 --  Negative indicates a left turn
  9.     end
  10.    
  11.     --  If you aren't already in the plane, go forward one block to enter
  12.     if not alreadyInPlane then
  13.         print("Digging into plane...")
  14.         DigStraightAhead(1)
  15.         print("Done digging into plane")
  16.     end
  17.    
  18.     while (rowCount <= width) do
  19.         print("PlaneCount: ", rowCount)
  20.         DigStraightAhead(depth-1)
  21.        
  22.        
  23.         --  We only need to execute the turn if you're not on the last set
  24.         if rowCount < width then
  25.             --  Code for turning right
  26.             if nextTurn > 0 then
  27.                 turtle.turnRight()
  28.                
  29.                 while true do --  Ensure that the turtle moves
  30.                     turtle.dig()
  31.                     res = turtle.forward()
  32.                     if res then
  33.                         break
  34.                     end
  35.                 end
  36.                
  37.                 turtle.turnRight()
  38.             --  Code for turning left
  39.             else
  40.                 turtle.turnLeft()
  41.                
  42.                 while true do --  Ensure that the turtle moves
  43.                     turtle.dig()
  44.                     res = turtle.forward()
  45.                     if res then
  46.                         break
  47.                     end
  48.                 end
  49.                
  50.                 turtle.turnLeft()
  51.             end
  52.            
  53.             --  Invert the turn so the next one goes the other way
  54.         end
  55.        
  56.         nextTurn = nextTurn * -1
  57.             rowCount = rowCount + 1
  58.        
  59.     end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement