Advertisement
DomMOW

Build Room Auto Fixed

Jan 8th, 2021
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.03 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.     digAbove()
  88.     moved = turtle.up()
  89.   end
  90.   yCurrent = yCurrent + 1
  91. end
  92.  
  93. function moveDown()
  94.   turtle.digDown()
  95.   moved = false
  96.   while not(moved) do
  97.     moved = turtle.down()
  98.   end
  99.   yCurrent = yCurrent - 1
  100. end
  101.  
  102. function goDown()
  103.   moved = false
  104.   while not(moved) do
  105.     turtle.digDown()  
  106.     moved = turtle.down()
  107.   end
  108.   yCurrent = yCurrent - 1
  109. end
  110.  
  111. function goUp()
  112.     moved = false
  113.     while not(moved) do
  114.         digAbove()
  115.       moved = turtle.up()
  116.     end
  117.     yCurrent = yCurrent + 1
  118. end
  119.  
  120. function upBreak()
  121.   digAbove()
  122.   goUp()
  123.   digAbove()
  124. end
  125.  
  126. function leftDig()
  127.   left()
  128.   moveForward()
  129.   digAbove()
  130.   digBelow()
  131.   while height > 0 do
  132.     upBreak()
  133.     height = height - 1
  134.   end
  135.   height = heightMax
  136.   while height > 0 do
  137.     moveDown()
  138.     height = height - 1
  139.   end
  140.   height = heightMax
  141.   left()
  142. end
  143.  
  144. function rightDig()
  145.   right()
  146.   moveForward()
  147.   digAbove()
  148.   digBelow()
  149.   while height > 0 do
  150.     upBreak()
  151.     height = height - 1
  152.   end
  153.   height = heightMax
  154.   while height > 0 do
  155.     moveDown()
  156.     height = height - 1
  157.   end
  158.   height = heightMax
  159.   right()
  160. end
  161.  
  162. function leftWalk()
  163.   left()
  164.   moveForward()
  165.   digAbove()
  166.   digBelow()
  167.   while height > 0 do
  168.     upBreak()
  169.     height = height - 1
  170.   end
  171.   height = heightMax
  172.   while height > 0 do
  173.     moveDown()
  174.     height = height - 1
  175.   end
  176.   height = heightMax
  177. end
  178.    
  179. function rightWalk()
  180.   right()
  181.   moveForward()
  182.   digAbove()
  183.   digBelow()
  184.   while height > 0 do
  185.     upBreak()
  186.     height = height - 1
  187.   end
  188.   height = heightMax
  189.   while height > 0 do
  190.     moveDown()
  191.     height = height - 1
  192.   end
  193.   height = heightMax
  194. end
  195.  
  196. function goto(xHome, zHome, yHome)
  197.     while yHome < yCurrent do
  198.         moveDown()
  199.     end
  200.     while yHome > yCurrent do
  201.         moveUp()
  202.     end
  203.     if xHome < xCurrent then
  204.       look("west")
  205.       while xHome < xCurrent do
  206.         moveForward()
  207.       end
  208.     end
  209.     if xHome > xCurrent then
  210.       look("east")
  211.       while xHome > xCurrent do
  212.         moveForward()
  213.       end
  214.     end
  215.     if zHome < zCurrent then
  216.       look("north")
  217.       while zHome < zCurrent do
  218.         moveForward()
  219.       end
  220.     end
  221.     if zHome > zCurrent then
  222.       look("south")
  223.       while zHome > zCurrent do
  224.         moveForward()
  225.       end
  226.     end
  227.     while not(orientation == startDirection) do
  228.         right()
  229.     end
  230. end
  231.  
  232. while true do
  233.   if lengthCurrent > 0 and ending == false then
  234.     moveForward()
  235.     digAbove()
  236.     digBelow()
  237.     while height > 0 do
  238.       upBreak()
  239.       height = height - 1
  240.     end
  241.     height = heightMax
  242.     while height > 0 do
  243.       moveDown()
  244.       height = height - 1
  245.     end
  246.     height = heightMax
  247.     placeTorch = placeTorch - 1
  248.     lengthCurrent = lengthCurrent - 1
  249.     if placeTorch <= 0 then
  250.       placeTorch = 10
  251.       turtle.placeDown()
  252.     end
  253.   end
  254.   if lengthCurrent <= 0 and turn == 1 and width > 0 then
  255.     width = width - 1
  256.     if width > 0 then
  257.       rightDig()
  258.       lengthCurrent = lengthMax
  259.       turn = 2
  260.       print("Turned Right")
  261.     end
  262.   end
  263.   if lengthCurrent <= 0 and turn == 2 and width > 0 then
  264.     width = width - 1
  265.     if width > 0 then
  266.       leftDig()
  267.       lengthCurrent = lengthMax
  268.       turn = 1
  269.       print("Turned Left")
  270.     end
  271.   end
  272.   if width <= 0 then
  273.     turnLast = turn
  274.     turn = 3
  275.     ending = true
  276.   end
  277.   if width <= 0 and turn == 3 and ending == true then
  278.     print("Final Walk Home")
  279.     goto(xHome, zHome, yHome)
  280.     kill = true
  281.     turn = 4
  282.   end
  283.   if kill == true then
  284.     print("Killing the Program")
  285.     error()
  286.   end
  287. end
  288.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement