itsmartin

Digroom

Dec 27th, 2012
964
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. -- Digroom by itsmartin
  2. -- Prompts you for a room size, and then digs it out.
  3. -- Doesn't check for fuel level, ensure the turtle has enough fuel before you start.
  4.  
  5. function dig3d(x, y, z)
  6.     print("Digging a room " .. x .. " by " .. y .. " by " .. z .. ".")
  7.     local layers = z
  8.     local ascend = 0
  9.    
  10.     while layers >= 2 do
  11.         dig2d(x, y, true)
  12.         turtle.down()
  13.         ascend = ascend + 1
  14.         if layers >= 3 then
  15.             turtle.digDown()
  16.             turtle.down()
  17.             ascend = ascend + 1
  18.         end
  19.         layers = layers - 2
  20.     end
  21.     if layers == 1 then
  22.         dig2d(x, y, false)
  23.     end
  24.    
  25.     for i = 1, ascend do
  26.         turtle.up()
  27.     end
  28. end
  29.  
  30. function dig2d(x, y, digDown)
  31.     local rows = x
  32.     local farEnd = false
  33.    
  34.     while rows > 0 do
  35.         dig1d(y, digDown)
  36.         farEnd = not farEnd
  37.         rows = rows - 1
  38.         if rows > 0 then
  39.             if farEnd then
  40.                 turtle.turnRight()
  41.                 digForward(digDown)
  42.                 turtle.turnRight()
  43.             else
  44.                 turtle.turnLeft()
  45.                 digForward(digDown)
  46.                 turtle.turnLeft()
  47.             end
  48.         else
  49.             -- Finished all rows, return back
  50.             if digDown then
  51.                 turtle.digDown()
  52.             end
  53.             if farEnd then
  54.                 turtle.turnLeft()
  55.                 turtle.turnLeft()
  56.                 for i = 1, y-1 do
  57.                     turtle.forward()
  58.                 end
  59.             end
  60.             turtle.turnRight()
  61.             for i = 1, x-1 do
  62.                 turtle.forward()
  63.             end
  64.             turtle.turnRight()
  65.         end
  66.     end
  67. end
  68.  
  69. function dig1d(y, digDown)
  70.     for i = 1, y-1 do
  71.         digForward(digDown)
  72.     end
  73. end
  74.  
  75. function digForward(digDown)
  76.     if digDown then
  77.         turtle.digDown()
  78.     end
  79.     turtle.dig()
  80.     local success = turtle.forward()
  81.     while not success do
  82.         turtle.dig()
  83.         success = turtle.forward()
  84.     end
  85. end
  86.  
  87. print("How wide do you want the room? (Number of blocks to the right of the turtle to dig, including the turtle's current block)")
  88. local x = tonumber(read())
  89.  
  90. print("How long do you want the room? (Number of blocks to the front of the turtle to dig, including the turtle's current block)")
  91. local y = tonumber(read())
  92.  
  93. print("How deep do you want the room? (Number of blocks below the turtle to dig, including the turtle's current block)")
  94. local z = tonumber(read())
  95.  
  96. dig3d(x,y,z)
Advertisement
Add Comment
Please, Sign In to add comment