Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Dig the snake-like branch mine four times.
- -- Returns frequently to drop off supplies.
- -- Places torches reasonably when they are placed in slot 16.
- function turnAround()
- for i=1,2 do
- turtle.turnLeft()
- end
- end
- function smartForward()
- --Dig a 2 high, 1 wide tunnel; gravel and sand friendly.
- while not turtle.forward() do
- turtle.dig()
- end
- while turtle.detectUp() do
- turtle.digUp()
- sleep(0.5)
- end
- end
- function snakeRight()
- -- Make a right turn in the snake.
- turtle.turnRight()
- for i=1,3 do
- smartForward()
- end
- turtle.select(16)
- turtle.placeUp()
- turtle.turnRight()
- end
- function snakeLeft()
- -- Make a left turn in the snake.
- turtle.turnLeft()
- for i=1,3 do
- smartForward()
- end
- turtle.select(16)
- turtle.placeUp()
- sleep(0.25)
- turtle.turnLeft()
- end
- function snakeSegment(l)
- -- Complete one segment of the snake of length l
- -- Turtle starts facing the wall for the first run
- for i=1,l do
- smartForward()
- if i % 10 == 0 then
- torchPlace()
- end
- end
- snakeRight()
- for i=1,l*2 do
- smartForward()
- if i % 10 == 0 then
- torchPlace()
- end
- end
- snakeLeft()
- for i=1,l do
- smartForward()
- if i % 10 == 0 then
- torchPlace()
- end
- end
- end
- function torchPlace()
- turtle.select(16)
- turtle.turnRight()
- sleep(0.25)
- turtle.placeUp()
- turtle.turnLeft()
- end
- function goHome(l)
- -- After a segment of length l, return to base
- -- Drop off items
- turtle.turnLeft()
- for i=1,l+2 do
- smartForward()
- end
- for j = 1,15 do
- turtle.select(j)
- turtle.drop()
- end
- end
- function resume(l)
- for i =1,l+2 do
- turtle.forward()
- end
- turtle.turnLeft()
- end
- local args = {...}
- if table.getn(args) < 1 then
- print("Usage: snakemine maxlength")
- print("maxlength is the length of the largest side branch. Must be multiple of 6")
- print("Make sure torches are in slot 16!")
- return
- end
- -- first arg is the maximum length of a tunnel off of
- local maxLength = tonumber(args[1])
- if maxLength % 6 ~= 0 then
- print("maxLength of " .. maxLength .. " is not a multiple of 6! Try again!")
- return
- end
- for quad = 1,4 do
- for i = 1,3 do smartForward() end
- turtle.turnLeft()
- for seg = 6,maxLength,6 do
- snakeSegment(seg)
- goHome(seg)
- if seg < maxLength then
- turnAround()
- resume(seg)
- else
- for i=1,4 do
- turtle.forward()
- end
- turtle.turnLeft()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment