Advertisement
VaMinion

area_level

Oct 10th, 2013
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. turtle_location = vector.new(0, 0, 0)
  2. area_size = vector.new(0, 0, 0)
  3.  
  4. -- Gets user input
  5. function get_size()
  6.     print("How long?")
  7.     area_size.x = tonumber(read())
  8.     print("How wide?")
  9.     area_size.y = tonumber(read())
  10.     print("How tall?")
  11.     area_size.z = tonumber(read())
  12. end
  13.  
  14. -- Move the turtle 1 to the right
  15. function move_right()
  16.     turtle.turnRight()
  17.     while turtle.detect() do
  18.         turtle.dig()
  19.     end
  20.     while not turtle.forward() do os.sleep(5) end
  21.     turtle.turnLeft()
  22.     turtle_location.y = turtle_location.y + 1
  23. end
  24.  
  25. -- Clears up to Z height.
  26. function clear_up()
  27.     repeat
  28.         while turtle.detectUp() do
  29.             turtle.digUp()
  30.         end
  31.         while not turtle.up() do os.sleep(5) end
  32.         turtle_location.z = turtle_location.z + 1
  33.     until turtle_location.z >= area_size.z-1
  34.  
  35.     repeat
  36.         while not turtle.down() do os.sleep(5) end
  37.         turtle_location.z = turtle_location.z - 1
  38.     until turtle_location.z == 0
  39. end
  40.  
  41. -- Dig straight up, then return to base height.
  42. -- Move forward 1. Repeat dig up procedure.
  43. -- Clears a row up to Z height.
  44. function x_clear()
  45.     print("starting x_clear")
  46.     clear_up()
  47.     while turtle_location.x < area_size.x-1 do
  48.         while turtle.detect() do
  49.             turtle.dig()
  50.         end
  51.         while not turtle.forward() do os.sleep(5) end
  52.         clear_up()
  53.         turtle_location.x = turtle_location.x + 1
  54.     end
  55.  
  56.     repeat
  57.         while not turtle.back() do os.sleep(5) end
  58.         turtle_location.x = turtle_location.x - 1
  59.     until turtle_location.x == 0
  60. end
  61.  
  62. function area_clear()
  63.     x_clear()
  64.     while turtle_location.y < (area_size.y-1) and area_size.y ~= 1 do
  65.         move_right()
  66.         x_clear()
  67.     end
  68.  
  69.     turtle.turnLeft()
  70.     repeat
  71.         while not turtle.forward() do os.sleep(5) end
  72.         turtle_location.y = turtle_location.y - 1
  73.     until turtle_location.y == 0
  74.  
  75.     turtle.turnRight()
  76. end
  77.  
  78. get_size()
  79. area_clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement