DomMOW

5xRxR Room

Dec 31st, 2020 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.46 KB | None | 0 0
  1. tunnelLengthMax = 4
  2. turn = 1
  3. turnLast = turn
  4. tunnelLengthCurrent = tunnelLengthMax
  5. placeTorch = 10
  6. widthMax = 4
  7. width = widthMax
  8. finishWalk = widthMax
  9. ending = false
  10. kill = false
  11.  
  12. function left()
  13.   turtle.turnLeft()
  14. end
  15.  
  16. function right()
  17.   turtle.turnRight()
  18. end
  19.  
  20. function moveForward()
  21.   while turtle.detect() do
  22.     turtle.dig()
  23.   end
  24.   moved = false
  25.   while not(moved) do
  26.     moved = turtle.forward()
  27.   end
  28. end
  29.  
  30. function digForward()
  31.   while turtle.detect() do
  32.     turtle.dig()
  33.   end
  34. end
  35.  
  36. function digBelow()
  37.   while turtle.detectDown() do
  38.     turtle.digDown()
  39.   end
  40. end
  41.  
  42. function digAbove()
  43.   while turtle.detectUp() do
  44.     turtle.digUp()
  45.   end
  46. end
  47.  
  48. function moveUp()
  49.   turtle.digUp()
  50.   moved = false
  51.   while not(moved) do
  52.     turtle.up()
  53.     moved = turtle.up()
  54.   end
  55. end
  56.  
  57. function goDown()
  58.   turtle.down()
  59. end
  60.  
  61. function goUp()
  62.   turtle.up()
  63. end
  64.  
  65. function moveDown()
  66.   turtle.digDown()
  67.   moved = false
  68.   while not(moved) do
  69.     moved = turtle.down()
  70.   end
  71. end
  72.  
  73. function leftDig()
  74.   turtle.turnLeft()
  75.   moveForward()
  76.     digAbove()
  77.     digBelow()
  78.     goUp()
  79.     digAbove()
  80.     goUp()
  81.     digAbove()
  82.     moveDown()
  83.     moveDown()
  84.   turtle.turnLeft()
  85. end
  86.  
  87. function rightDig()
  88.   turtle.turnRight()
  89.   moveForward()
  90.     digAbove()
  91.     digBelow()
  92.     goUp()
  93.     digAbove()
  94.     goUp()
  95.     digAbove()
  96.     moveDown()
  97.     moveDown()
  98.   turtle.turnRight()
  99. end
  100.  
  101. function leftWalk()
  102.   turtle.turnLeft()
  103.   moveForward()
  104.     digAbove()
  105.     digBelow()
  106.     goUp()
  107.     digAbove()
  108.     goUp()
  109.     digAbove()
  110.     moveDown()
  111.     moveDown()
  112. end
  113.    
  114. function rightWalk()
  115.   turtle.turnRight()
  116.   moveForward()
  117.     digAbove()
  118.     digBelow()
  119.     goUp()
  120.     digAbove()
  121.     goUp()
  122.     digAbove()
  123.     moveDown()
  124.     moveDown()
  125. end
  126.  
  127. while true do
  128.   if tunnelLengthCurrent > 0 and ending == false then
  129.     moveForward()
  130.     digAbove()
  131.     digBelow()
  132.     goUp()
  133.     digAbove()
  134.     goUp()
  135.     digAbove()
  136.     moveDown()
  137.     moveDown()
  138.     placeTorch = placeTorch - 1
  139.     tunnelLengthCurrent = tunnelLengthCurrent - 1
  140.     if placeTorch <= 0 then
  141.       placeTorch = 10
  142.       turtle.placeDown()
  143.     end
  144.   end
  145.   if tunnelLengthCurrent <= 0 and turn == 1 and width > 0 then
  146.     width = width - 1
  147.     if width > 0 then
  148.       rightDig()
  149.       tunnelLengthCurrent = tunnelLengthMax
  150.       turn = 2
  151.       print("Turned Right")
  152.     end
  153.   end
  154.   if tunnelLengthCurrent <= 0 and turn == 2 and width > 0 then
  155.     width = width - 1
  156.     if width > 0 then
  157.       leftDig()
  158.       tunnelLengthCurrent = tunnelLengthMax
  159.       turn = 1
  160.       print("Turned Left")
  161.     end
  162.   end
  163.   if width <= 0 then
  164.     turnLast = turn
  165.     turn = 3
  166.     ending = true
  167.   end
  168.   if width <= 0 and turn == 3 and ending == true then
  169.     print("Final Walk Home")
  170.     if turnLast == 1 then
  171.       tunnelLengthCurrent = tunnelLengthMax
  172.       left()
  173.       finishWalk = finishWalk - 1
  174.       while finishWalk > 0 do
  175.         moveForward()
  176.         finishWalk = finishWalk - 1
  177.       end
  178.       while tunnelLengthCurrent > 0 do
  179.         moveForward()
  180.         tunnelLengthCurrent = tunnelLengthCurrent - 1
  181.       end
  182.     end
  183.     if turnLast == 2 then
  184.       right()
  185.       finishWalk = finishWalk - 1
  186.       while finishWalk > 0 do
  187.         moveForward()
  188.         finishWalk = finishWalk - 1
  189.       end
  190.       right()
  191.     end
  192.     kill = true
  193.     turn = 4
  194.   end
  195.   if kill == true then
  196.     print("Killing the Program")
  197.     error()
  198.   end
  199. end
Add Comment
Please, Sign In to add comment