Advertisement
VaMinion

bc_quarry_prep

Nov 4th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.78 KB | None | 0 0
  1. -- Put bricks in slot 1, landmark in slot 2
  2.  
  3. turtle_pos = vector.new(0, 0, 0)
  4.   turtle_pos.x = 0
  5.   turtle_pos.y = 0
  6.   turtle_pos.z = 0
  7. square_size = vector.new(0, 0, 0)
  8.  
  9. function place_corner()
  10.   -- Move down 1 square.
  11.   while not turtle.down() do
  12.     turtle.digDown()
  13.     os.sleep(1)
  14.   end
  15.  
  16.   -- Decrement turtle's Z
  17.   turtle_pos.z = turtle_pos.z - 1
  18.  
  19.   -- If no block is present, place block.
  20.   if not turtle.detectDown() then
  21.     turtle.select(1)
  22.     turtle.placeDown()
  23.   end
  24.  
  25.   -- Move up 1 level.
  26.   while not turtle.up() do
  27.     if turtle.detectUp() then turtle.digUp() end
  28.     os.sleep(1)
  29.   end
  30.  
  31.   -- Increment turtle's Z coordinate because it 1 block above where the quarry will be placed.
  32.   turtle_pos.z = turtle_pos.z + 1
  33.  
  34.   -- Place landmark.
  35.   turtle.select(2)
  36.   turtle.placeDown()
  37. end
  38.  
  39. -- Go through following code and convert to functions as needed.
  40.  
  41. -- Get input
  42. -- Prompt for length and width.
  43.  
  44. function mark_quarry()
  45.   print("How long?")
  46.   square_size.x = tonumber(read()) - 1
  47.   print("How wide?")
  48.   square_size.y = tonumber(read()) - 1
  49.  
  50.   -- Place bricks in slot 1, landmark in slot 2
  51.   -- Turtle starts in lower left corner. Place block beneath turtle if no block there.
  52.   if not turtle.detectDown() then
  53.     turtle.select(1)
  54.     turtle.placeDown()
  55.   end
  56.  
  57.   while not turtle.up() do
  58.     turtle.digUp()
  59.     os.sleep(2)
  60.   end
  61.  
  62.   -- Increment turtle's Z coordinate because it 1 block above where the quarry will be placed.
  63.   turtle_pos.z = 1
  64.  
  65.   -- Place the lower left landmark.
  66.   turtle.select(2)
  67.   turtle.placeDown()
  68.  
  69.   -- Move to upper left corner:
  70.   repeat
  71.     while not turtle.forward() do
  72.       if turtle.detect() then turtle.dig() end
  73.       os.sleep(1)
  74.     end
  75.     turtle_pos.y = turtle_pos.y +1
  76.   until turtle_pos.y >= square_size.y
  77.  
  78.   -- Place upper left landmark
  79.   print("Placing upper left beacon")
  80.   place_corner()
  81.  
  82.   -- Move to upper right.
  83.   turtle.turnRight()
  84.   repeat
  85.     while not turtle.forward() do
  86.       if turtle.detect() then turtle.dig() end
  87.       os.sleep(1)
  88.     end
  89.     turtle_pos.x = turtle_pos.x + 1
  90.   until turtle_pos.x >= square_size.x
  91.  
  92.   -- Place upper right
  93.   print("Placing upper right beacon")
  94.   place_corner()
  95.  
  96.   -- Move to lower right
  97.   turtle.turnRight()
  98.   repeat
  99.     while not turtle.forward() do
  100.       if turtle.detect() then turtle.dig() end
  101.       os.sleep(1)
  102.     end
  103.     turtle_pos.y = turtle_pos.y - 1
  104.   until turtle_pos.y <= 0
  105.  
  106.   -- Place lower right
  107.   print("Place lower right beacon")
  108.   place_corner()
  109.  
  110.   -- Return to just above point of origin.
  111.   turtle.turnRight()
  112.   repeat
  113.     while not turtle.forward() do
  114.       if turtle.detect() then turtle.dig() end
  115.       os.sleep(1)
  116.     end
  117.     turtle_pos.x = turtle_pos.x - 1
  118.   until turtle_pos.x <= 0
  119. end
  120.  
  121. mark_quarry()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement