Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- turtle_location = vector.new(0, 0, 0)
- area_size = vector.new(0, 0, 0)
- turtle_slot = 1
- -- Gets user input
- function get_size()
- -- Local variables
- local invCount = 0 -- Count of bricks in the turtle's inventory.
- local totalArea = 0 -- Total area to be filled in terms of minecraft bricks.
- print("How long?")
- area_size.x = tonumber(read())
- print("How wide?")
- area_size.y = tonumber(read())
- -- Calculates if there are enough bricks in the inventory to fill the selected area.
- print("Calculating area fill size vs. bricks in inventory...")
- totalArea = area_size.x * area_size.y
- for i=1, 16 do
- invCount = invCount + turtle.getItemCount(i)
- end
- if invCount < totalArea then
- return false
- else
- return true
- end
- end
- -- Move right.
- function move_right()
- turtle.turnRight()
- if turtle.detect() then
- turtle.dig()
- end
- while not turtle.forward() do
- os.sleep(5)
- end
- turtle.turnLeft()
- turtle_location.y = turtle_location.y + 1
- end
- -- Block placement subroutine
- function place_block()
- if not turtle.detectDown() then
- while not turtle.placeDown() do
- turtle_slot = turtle_slot + 1
- turtle.select(turtle_slot)
- end
- end
- end
- -- X Fill
- function x_fill()
- repeat
- -- If it does not detect a block under the turtle, it tries to place a block below.
- place_block()
- while turtle_location.x < area_size.x and not turtle.forward() do
- if turtle.detect() then turtle.dig() end
- os.sleep(5)
- end
- turtle_location.x = turtle_location.x + 1
- until turtle_location.x >= area_size.x-1
- -- Refine logic later; for now this will place the blocks.
- -- Need to alter loop so that the turtle places a block every time it moves forward.
- place_block()
- while turtle_location.x > 0 do
- while not turtle.back() do
- os.sleep(5)
- end
- turtle_location.x = turtle_location.x - 1
- end
- end
- -- Fills an area
- function area_fill()
- if not get_size() then
- print("Insufficient blocks in inventory.")
- return
- end
- x_fill()
- while turtle_location.y < area_size.y-1 and area_size.y ~= 1 do
- move_right()
- x_fill()
- end
- turtle.turnLeft()
- repeat
- while not turtle.forward() do
- os.sleep(5)
- end
- turtle_location.y = turtle_location.y - 1
- until turtle_location.y == 0
- turtle.turnRight()
- end
- -- Execute the program
- area_fill()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement