Advertisement
VaMinion

layer_maker

Oct 16th, 2013
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. turtle_location = vector.new(0, 0, 0)
  2. area_size = vector.new(0, 0, 0)
  3. turtle_slot = 1
  4.  
  5. -- Gets user input
  6. function get_size()
  7.  -- Local variables
  8.  local invCount = 0 -- Count of bricks in the turtle's inventory.
  9.  local totalArea = 0 -- Total area to be filled in terms of minecraft bricks.
  10.  print("How long?")
  11.  area_size.x = tonumber(read())
  12.  print("How wide?")
  13.  area_size.y = tonumber(read())
  14.  
  15.  -- Calculates if there are enough bricks in the inventory to fill the selected area.
  16.  print("Calculating area fill size vs. bricks in inventory...")
  17.  totalArea = area_size.x * area_size.y
  18.  for i=1, 16 do
  19.   invCount = invCount + turtle.getItemCount(i)
  20.  end
  21.  if invCount < totalArea then
  22.   return false
  23.  else
  24.   return true
  25.  end
  26. end
  27.  
  28. -- Move right.
  29. function move_right()
  30.         turtle.turnRight()
  31.         if turtle.detect() then
  32.                 turtle.dig()
  33.         end
  34.         while not turtle.forward() do
  35.           os.sleep(5)
  36.         end
  37.         turtle.turnLeft()
  38.         turtle_location.y = turtle_location.y + 1
  39. end
  40.  
  41. -- Block placement subroutine
  42. function place_block()
  43.   if not turtle.detectDown() then
  44.     while not turtle.placeDown() do
  45.       turtle_slot = turtle_slot + 1
  46.       turtle.select(turtle_slot)
  47.     end
  48.   end
  49. end
  50. -- X Fill
  51. function x_fill()
  52.   repeat
  53.     -- If it does not detect a block under the turtle, it tries to place a block below.
  54.     place_block()
  55.  
  56.     while turtle_location.x < area_size.x and not turtle.forward() do
  57.       if turtle.detect() then turtle.dig() end
  58.       os.sleep(5)
  59.     end
  60.     turtle_location.x = turtle_location.x + 1
  61.   until turtle_location.x >= area_size.x-1
  62.  
  63.   -- Refine logic later; for now this will place the blocks.
  64.   -- Need to alter loop so that the turtle places a block every time it moves forward.
  65.   place_block()
  66.  
  67.   while turtle_location.x > 0 do
  68.     while not turtle.back() do
  69.       os.sleep(5)
  70.     end
  71.     turtle_location.x = turtle_location.x - 1
  72.   end
  73. end
  74.  
  75. -- Fills an area
  76. function area_fill()
  77.   if not get_size() then
  78.     print("Insufficient blocks in inventory.")
  79.     return
  80.   end
  81.  
  82.   x_fill()
  83.   while turtle_location.y < area_size.y-1 and area_size.y ~= 1 do
  84.     move_right()
  85.     x_fill()
  86.   end
  87.  
  88.   turtle.turnLeft()
  89.  
  90.   repeat
  91.     while not turtle.forward() do
  92.       os.sleep(5)
  93.     end
  94.     turtle_location.y = turtle_location.y - 1
  95.   until turtle_location.y == 0
  96.  
  97.   turtle.turnRight()
  98. end
  99.  
  100. -- Execute the program
  101. area_fill()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement