Advertisement
DomMOW

BuildRoomExtra

Jan 10th, 2021 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.07 KB | None | 0 0
  1. --Min is 3 for H--
  2. lengthMax = 50
  3. widthMax = 3
  4. heightMax = 3
  5. orientation = 4
  6. --N=4, E=3, S=2, W=1--
  7. orientations = {"north", "east", "south", "west"}
  8. startDirection = orientation
  9.  
  10. xCurrent = 0
  11. zCurrent = 0
  12. yCurrent = 0
  13.  
  14. xHome = 0
  15. zHome = 0
  16. yHome = 0
  17.  
  18. zDiff = {-1, 0, 1, 0}
  19. xDiff = {0, 1, 0 ,-1}
  20.  
  21. turn = 1
  22. turnLast = turn
  23. lengthCurrent = lengthMax
  24. placeTorch = 10
  25. width = widthMax
  26. finishWalk = widthMax
  27. heightMax = heightMax - 3
  28. height = heightMax
  29. ending = false
  30. kill = false
  31.  
  32. function left()
  33.   orientation = orientation - 1
  34.   orientation = (orientation - 1) % 4
  35.   orientation = orientation + 1
  36.  
  37.   turtle.turnLeft()
  38. end
  39.  
  40. function right()
  41.   orientation = orientation - 1
  42.   orientation = (orientation + 1) % 4
  43.   orientation = orientation + 1
  44.  
  45.   turtle.turnRight()
  46. end
  47.  
  48. function look(direction)
  49.     while direction ~= orientations[orientation] do
  50.       right()
  51.     end
  52. end
  53.  
  54. function moveForward()
  55.   while turtle.detect() do
  56.     turtle.dig()
  57.   end
  58.   moved = false
  59.   while not(moved) do
  60.     moved = turtle.forward()
  61.   end
  62.   xCurrent = xCurrent + xDiff[orientation]
  63.   zCurrent = zCurrent + zDiff[orientation]
  64. end
  65.  
  66. function digForward()
  67.   while turtle.detect() do
  68.     turtle.dig()
  69.   end
  70. end
  71.  
  72. function digBelow()
  73.   while turtle.detectDown() do
  74.     turtle.digDown()
  75.   end
  76. end
  77.  
  78. function digAbove()
  79.   while turtle.detectUp() do
  80.     turtle.digUp()
  81.   end
  82. end
  83.  
  84. function moveUp()
  85.   turtle.digUp()
  86.   moved = false
  87.   while not(moved) do
  88.     digAbove()
  89.     moved = turtle.up()
  90.   end
  91.   yCurrent = yCurrent + 1
  92. end
  93.  
  94. function moveDown()
  95.   turtle.digDown()
  96.   moved = false
  97.   while not(moved) do
  98.     moved = turtle.down()
  99.   end
  100.   yCurrent = yCurrent - 1
  101. end
  102.  
  103. function goDown()
  104.   moved = false
  105.   while not(moved) do
  106.     turtle.digDown()  
  107.     moved = turtle.down()
  108.   end
  109.   yCurrent = yCurrent - 1
  110. end
  111.  
  112. function goUp()
  113.     moved = false
  114.     while not(moved) do
  115.         digAbove()
  116.       moved = turtle.up()
  117.     end
  118.     yCurrent = yCurrent + 1
  119. end
  120.  
  121. function upBreak()
  122.   digAbove()
  123.   goUp()
  124.   digAbove()
  125. end
  126.  
  127. function leftDig()
  128.   left()
  129.   moveForward()
  130.   digAbove()
  131.   digBelow()
  132.   while height > 0 do
  133.     upBreak()
  134.     height = height - 1
  135.   end
  136.   height = heightMax
  137.   while height > 0 do
  138.     moveDown()
  139.     height = height - 1
  140.   end
  141.   height = heightMax
  142.   left()
  143. end
  144.  
  145. function rightDig()
  146.   right()
  147.   moveForward()
  148.   digAbove()
  149.   digBelow()
  150.   while height > 0 do
  151.     upBreak()
  152.     height = height - 1
  153.   end
  154.   height = heightMax
  155.   while height > 0 do
  156.     moveDown()
  157.     height = height - 1
  158.   end
  159.   height = heightMax
  160.   right()
  161. end
  162.  
  163. function leftWalk()
  164.   left()
  165.   moveForward()
  166.   digAbove()
  167.   digBelow()
  168.   while height > 0 do
  169.     upBreak()
  170.     height = height - 1
  171.   end
  172.   height = heightMax
  173.   while height > 0 do
  174.     moveDown()
  175.     height = height - 1
  176.   end
  177.   height = heightMax
  178. end
  179.    
  180. function rightWalk()
  181.   right()
  182.   moveForward()
  183.   digAbove()
  184.   digBelow()
  185.   while height > 0 do
  186.     upBreak()
  187.     height = height - 1
  188.   end
  189.   height = heightMax
  190.   while height > 0 do
  191.     moveDown()
  192.     height = height - 1
  193.   end
  194.   height = heightMax
  195. end
  196.  
  197. function goto(xHome, zHome, yHome)
  198.     while yHome < yCurrent do
  199.         moveDown()
  200.     end
  201.     while yHome > yCurrent do
  202.         moveUp()
  203.     end
  204.     if xHome < xCurrent then
  205.       look("west")
  206.       while xHome < xCurrent do
  207.         moveForward()
  208.       end
  209.     end
  210.     if xHome > xCurrent then
  211.       look("east")
  212.       while xHome > xCurrent do
  213.         moveForward()
  214.       end
  215.     end
  216.     if zHome < zCurrent then
  217.       look("north")
  218.       while zHome < zCurrent do
  219.         moveForward()
  220.       end
  221.     end
  222.     if zHome > zCurrent then
  223.       look("south")
  224.       while zHome > zCurrent do
  225.         moveForward()
  226.       end
  227.     end
  228.     while not(orientation == startDirection) do
  229.         right()
  230.     end
  231. end
  232.  
  233. while true do
  234.   if lengthCurrent > 0 and ending == false then
  235.     moveForward()
  236.     digAbove()
  237.     digBelow()
  238.     while height > 0 do
  239.       upBreak()
  240.       height = height - 1
  241.     end
  242.     height = heightMax
  243.     while height > 0 do
  244.       moveDown()
  245.       height = height - 1
  246.     end
  247.     height = heightMax
  248.     placeTorch = placeTorch - 1
  249.     lengthCurrent = lengthCurrent - 1
  250.     if placeTorch <= 0 then
  251.       placeTorch = 10
  252.       turtle.placeDown()
  253.     end
  254.   end
  255.   if lengthCurrent <= 0 and turn == 1 and width > 0 then
  256.     width = width - 1
  257.     if width > 0 then
  258.       rightDig()
  259.       lengthCurrent = lengthMax
  260.       turn = 2
  261.       print("Turned Right")
  262.     end
  263.   end
  264.   if lengthCurrent <= 0 and turn == 2 and width > 0 then
  265.     width = width - 1
  266.     if width > 0 then
  267.       leftDig()
  268.       lengthCurrent = lengthMax
  269.       turn = 1
  270.       print("Turned Left")
  271.     end
  272.   end
  273.   if width <= 0 then
  274.     turnLast = turn
  275.     turn = 3
  276.     ending = true
  277.   end
  278.   if width <= 0 and turn == 3 and ending == true then
  279.     print("Final Walk Home")
  280.     goto(xHome, zHome, yHome)
  281.     kill = true
  282.     turn = 4
  283.   end
  284.   if kill == true then
  285.     print("Killing the Program")
  286.     error()
  287.   end
  288. end
  289.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement