Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- determine movement direction
- local move, detect = turtle.detectDown() and turtle.up
- or turtle.detectUp() and turtle.down
- or error("Place facing one of the corners.", 0),
- turtle.detectDown() and turtle.detectUp
- or turtle.detectDown
- local dir = move == turtle.up and true or false -- 1 if moving up, 0 otherwise
- if not turtle.detect() then error("Place facing one of the corners.", 0) end
- local _print = print
- local function print(...)
- _print("["..(os.clock() or "X").."]", ...)
- end
- -- moves and digs
- local function bottom()
- print("BOTTOM - DIG")
- turtle.dig()
- turtle.digDown()
- if dir then
- print("BOTTOM - MOVE")
- move()
- return
- end
- print("BOTTOM - NO MOVE")
- end
- local function sides()
- print("SIDE - DIG")
- turtle.dig()
- print("SIDE - MOVE")
- move()
- end
- local function top()
- print("TOP - DIG")
- turtle.dig()
- turtle.digUp()
- if not dir then
- print("TOP - MOVE")
- move()
- return
- end
- print("TOP - NO MOVE")
- end
- local t1, t2 = dir and bottom or top, dir and top or bottom
- local function switch()
- print("SWITCH - BACK")
- turtle.back()
- print("SWITCH - TURN")
- turtle.turnLeft()
- turtle.turnLeft()
- -- toggle the movement direction to the other direction
- move = move == turtle.down and turtle.up or turtle.down
- detect = detect == turtle.detectDown and turtle.detectUp or turtle.detectDown
- dir = not dir
- end
- -- actually move. If starting from the top, go down then up, otherwise go up then down.
- print("Turtle is positioned at", dir and "bottom" or "top", "corner of portal.")
- t1()
- while not detect() do
- sides()
- end
- local count = 0
- repeat
- count = count + 1
- t2()
- until not turtle.back()
- switch()
- t2()
- while not detect() do
- sides()
- end
- for i = 1, count do
- t1()
- if i ~= count then
- turtle.back()
- end
- end
- print("Done.")
Add Comment
Please, Sign In to add comment