Advertisement
DomMOW

BuildRoomAuto

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