Advertisement
thorax232

ComputerCraft - Clear Space

Jun 8th, 2014
1,512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1. function turnAround()
  2.     turtle.turnLeft()
  3.     turtle.turnLeft()
  4. end
  5.  
  6. function sandDig()
  7.     while turtle.detect() do
  8.         turtle.dig()
  9.     end
  10. end
  11.  
  12. function forward(n) -- Forwad and dig
  13.     for i=1,n do
  14.         sandDig()
  15.         turtle.forward()
  16.     end
  17. end
  18.  
  19. function down(n) -- Down n times
  20.     for i = 1,n do
  21.         turtle.down()
  22.     end
  23. end
  24.  
  25. function digL() -- Dig length
  26.     if l > 0 then
  27.         for i = 1,l-1 do
  28.             sandDig()
  29.             turtle.forward()
  30.         end
  31.     end
  32. end
  33.  
  34. function nextRow()
  35.     if count % 2 == 0 then -- Right for even number rows
  36.         turtle.turnRight()
  37.         sandDig()
  38.         turtle.forward()
  39.         turtle.turnRight()
  40.     else -- Left for odd number rows
  41.         turtle.turnLeft()
  42.         sandDig()
  43.         turtle.forward()
  44.         turtle.turnLeft()
  45.     end
  46.     count = count + 1
  47. end
  48.  
  49. function section()
  50.     for i = 1,w do
  51.         digL() -- Dig out length and move to next rows
  52.         if i < w then -- Won't start extra row at end
  53.             nextRow() -- Digs one whole section
  54.         end
  55.     end
  56. end
  57.  
  58. function nextSection()
  59.     turtle.digUp() -- Moves to next section (up)
  60.     turtle.up()
  61.     turnAround()
  62. end
  63.  
  64. function goingUp() -- Digs base section, moves up
  65.     for i = 1,h do -- Drives whole program
  66.         if w % 2 == 0 then -- Even number widths need alternating nextRow
  67.             if i % 2 == 0 then -- ^ orientations.
  68.                 count = 0
  69.             else
  70.                 count = 1
  71.             end
  72.         else
  73.             count = 1
  74.         end
  75.         section()
  76.         if i < h then -- Won't go up extra block at end
  77.             nextSection()
  78.         end
  79.     end
  80. end
  81.  
  82. function goingDown() -- Go to lowest level first
  83.     for i = 1,d do
  84.         turtle.digDown()
  85.         turtle.down()
  86.     end
  87. end
  88.  
  89. count = 1 -- For nextRow function
  90.  
  91. print("How far forward? (length)")
  92. l = tonumber(read()) -- Length
  93. print("How far left? (width)")
  94. w = tonumber(read()) -- Width
  95. print("How tall? (at least 1)")
  96. h = tonumber(read()) -- Height
  97. print("How deep? (0 for this level)")
  98. d = tonumber(read()) -- Depth
  99.  
  100. if d > 0 then
  101.     print("Going down!")
  102.     goingDown()
  103. end
  104. if h > 0 then
  105.     print("Here I go!")
  106.     goingUp()
  107. end
  108. if h > 0 then
  109.     print("Complete.")
  110.     down(h) -- Parks turtle in bottom corner
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement