fatboychummy

Portal Deconstructor

Apr 20th, 2021 (edited)
280
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- determine movement direction
  2. local move, detect = turtle.detectDown() and turtle.up
  3.                   or turtle.detectUp() and turtle.down
  4.                   or error("Place facing one of the corners.", 0),
  5.                      turtle.detectDown() and turtle.detectUp
  6.                   or turtle.detectDown
  7. local dir = move == turtle.up and true or false -- 1 if moving up, 0 otherwise
  8. if not turtle.detect() then error("Place facing one of the corners.", 0) end
  9.  
  10. local _print = print
  11. local function print(...)
  12.   _print("["..(os.clock() or "X").."]", ...)
  13. end
  14.  
  15. -- moves and digs
  16. local function bottom()
  17.   print("BOTTOM - DIG")
  18.   turtle.dig()
  19.   turtle.digDown()
  20.   if dir then
  21.     print("BOTTOM - MOVE")
  22.     move()
  23.     return
  24.   end
  25.   print("BOTTOM - NO MOVE")
  26. end
  27. local function sides()
  28.   print("SIDE - DIG")
  29.   turtle.dig()
  30.   print("SIDE - MOVE")
  31.   move()
  32. end
  33. local function top()
  34.   print("TOP - DIG")
  35.   turtle.dig()
  36.   turtle.digUp()
  37.   if not dir then
  38.     print("TOP - MOVE")
  39.     move()
  40.     return
  41.   end
  42.   print("TOP - NO MOVE")
  43. end
  44. local t1, t2 = dir and bottom or top, dir and top or bottom
  45. local function switch()
  46.   print("SWITCH - BACK")
  47.   turtle.back()
  48.   print("SWITCH - TURN")
  49.   turtle.turnLeft()
  50.   turtle.turnLeft()
  51.  
  52.   -- toggle the movement direction to the other direction
  53.   move = move == turtle.down and turtle.up or turtle.down
  54.   detect = detect == turtle.detectDown and turtle.detectUp or turtle.detectDown
  55.   dir = not dir
  56. end
  57.  
  58.  
  59. -- actually move. If starting from the top, go down then up, otherwise go up then down.
  60. print("Turtle is positioned at", dir and "bottom" or "top", "corner of portal.")
  61. t1()
  62. while not detect() do
  63.   sides()
  64. end
  65.  
  66. local count = 0
  67. repeat
  68.   count = count + 1
  69.   t2()
  70. until not turtle.back()
  71.  
  72. switch()
  73.  
  74. t2()
  75. while not detect() do
  76.   sides()
  77. end
  78. for i = 1, count do
  79.   t1()
  80.   if i ~= count then
  81.     turtle.back()
  82.   end
  83. end
  84. print("Done.")
RAW Paste Data