Advertisement
DomMOW

Shear Sheep Auto Home 3x3

Jan 2nd, 2021 (edited)
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.43 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. function upMove()
  18.     yCurrent = yCurrent + 1
  19.     turtle.up()
  20. end
  21.  
  22. function downMove()
  23.     yCurrent = yCurrent - 1
  24.     turtle.down()
  25. end
  26.  
  27. function forwardMove()
  28.     xCurrent = xCurrent + xDiff[orientation]
  29.     zCurrent = zCurrent + zDiff[orientation]
  30.  
  31.     turtle.forward()
  32. end
  33.  
  34. function backMove()
  35.     xCurrent = xCurrent - xDiff[orientation]
  36.     zCurrent = zCurrent - zDiff[orientation]
  37.  
  38.     turtle.back()
  39. end
  40.  
  41. function leftMove()
  42.     orientation = orientation - 1
  43.     orientation = (orientation - 1) % 4
  44.     orientation = orientation + 1
  45.  
  46.     turtle.turnLeft()
  47.     forwardMove()
  48. end
  49.  
  50. function rightMove()
  51.     orientation = orientation - 1
  52.     orientation = (orientation + 1) % 4
  53.     orientation = orientation + 1
  54.  
  55.     turtle.turnRight()
  56.     forwardMove()
  57. end
  58.  
  59. function left()
  60.     orientation = orientation - 1
  61.     orientation = (orientation - 1) % 4
  62.     orientation = orientation + 1
  63.  
  64.     turtle.turnLeft()
  65. end
  66.  
  67. function right()
  68.     orientation = orientation - 1
  69.     orientation = (orientation + 1) % 4
  70.     orientation = orientation + 1
  71.  
  72.     turtle.turnRight()
  73. end
  74.  
  75. function look(direction)
  76.     while direction ~= orientations[orientation] do
  77.       right()
  78.     end
  79. end
  80.  
  81. function goto(xHome, zHome, yHome)
  82.  
  83.     while yHome < yCurrent do
  84.         downMove()
  85.     end
  86.     while yHome > yCurrent do
  87.         upMove()
  88.     end
  89.     if xHome < xCurrent then
  90.       look("west")
  91.       while xHome < xCurrent do
  92.         forwardMove()
  93.       end
  94.     end
  95.     if xHome > xCurrent then
  96.       look("east")
  97.       while xHome > xCurrent do
  98.         forwardMove()
  99.       end
  100.     end
  101.     if zHome < zCurrent then
  102.       look("north")
  103.       while zHome < zCurrent do
  104.         forwardMove()
  105.       end
  106.     end
  107.     if zHome > zCurrent then
  108.       look("south")
  109.       while zHome > zCurrent do
  110.         forwardMove()
  111.       end
  112.     end
  113.     while not(orientation == startDirection) do
  114.         right()
  115.     end
  116. end
  117.  
  118. function shearDown()
  119.     while not(turtle.placeDown()) do
  120.         turtle.placeDown()
  121.         turtle.suckUp()
  122.     end
  123. end
  124.  
  125. function dropOff()
  126.     turtle.select(2)
  127.     while turtle.getItemCount() > 0 do
  128.         turtle.drop()
  129.     end
  130.     turtle.select(1)
  131. end
  132.  
  133. function forwardShear()
  134.     forwardMove()
  135.     shearDown()
  136. end
  137.  
  138. function leftShear()
  139.     leftMove()
  140.     shearDown()
  141. end
  142.  
  143. function rightShear()
  144.     rightMove()
  145.     shearDown()
  146. end
  147.  
  148. function startDrop()
  149.     backMove()
  150.     left()
  151.     dropOff()
  152. end
  153.  
  154. function backToStart()
  155.     leftMove()
  156.     leftMove()
  157.     forwardMove()
  158.     left()
  159. end
  160.  
  161. function shearCheck()
  162.     turtle.select(1)
  163.     if turtle.getItemCount() == 0 then
  164.         goto(0, 0, 0)
  165.     end
  166. end
  167.  
  168. function shearThree()
  169.     shearDown()
  170.     shearCheck()
  171.     forwardShear()
  172.     shearCheck()
  173.     forwardShear()
  174.     shearCheck()
  175.     leftMove()
  176.     shearCheck()
  177.     left()
  178.     shearCheck()
  179.     forwardShear()
  180.     shearCheck()
  181.     forwardShear()
  182.     shearCheck()
  183.     rightMove()
  184.     shearCheck()
  185.     right()
  186.     shearCheck()
  187.     forwardShear()
  188.     shearCheck()
  189.     forwardShear()
  190.     shearCheck()
  191.     startDrop()
  192.     shearCheck()
  193.     backToStart()
  194.     shearCheck()
  195. end
  196.  
  197. while true do
  198.     shearThree()
  199.     sleep(2)
  200. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement