Advertisement
InkSplotch56

Untitled

Jul 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. --FORWARD, RIGHT, BACK, LEFT
  2. possibleDirections = {1, 2, 3, 4}
  3. currXYZF = {0, 4, 0, 1}
  4. maxSupport = 25
  5.  
  6. function setXYZ(newXYZ)
  7. currXYZF[1] = newXYZ[1]
  8. currXYZF[2] = newXYZ[2]
  9. currXYZF[3] = newXYZ[3]
  10. end
  11.  
  12.  
  13. function setOrientation(newOrientation)
  14. currXYZF[4] = newOrientation
  15. end
  16.  
  17.  
  18. function adjustOrientation(turnDir)
  19. currentIndex = currXYZF[4]
  20. if turnDir == "left" then
  21. newIndex = (currentIndex - 1) % 4
  22. elseif turnDir == "right" then
  23. newIndex = (currentIndex + 1) % 4
  24. end
  25. setOrientation(newIndex)
  26. if turnDir == "left" then
  27. turtle.turnLeft()
  28. elseif turnDir == "right" then
  29. turtle.turnRight()
  30. end
  31. end
  32.  
  33.  
  34. function faceOrientation(desiredOrientation)
  35. requiredChange = desiredOrientation - currXYZF[4]
  36. if requiredChange == 0 then
  37. return
  38. elseif requiredChange > 0 then
  39. changeSign = "right"
  40. elseif requiredChange < 0 then
  41. changeSign = "left"
  42. end
  43. for _ = 1, math.abs(requiredChange) do
  44. adjustOrientation(changeSign)
  45. end
  46. end
  47.  
  48.  
  49. function moveDirection(moveFunc, detectFunc, digFunc, attackFunc, maxDigStack, newX, newY, newZ)
  50. local moveSuccess = moveFunc()
  51. if not moveSuccess then
  52. local digCount = 0
  53. local digSuccess = digFunc()
  54. moveSuccess = moveFunc()
  55. while not moveSuccess and digCount < maxDigStack do
  56. if detectFunc() then
  57. digFunc()
  58. digCount = digCount + 1
  59. else
  60. attackFunc()
  61. end
  62. movementSuccess = moveFunc()
  63. end
  64. end
  65. currXYZF[1] = newX
  66. currXYZF[2] = newY
  67. currXYZF[3] = newZ
  68. end
  69.  
  70.  
  71. function moveForward()
  72. local newX, newZ
  73. local currentOrientation = currXYZF[4]
  74. if currentOrientation == 1 then
  75. newZ = currXYZF[3] + 1
  76. newX = currXYZF[1]
  77. elseif currentOrientation == 2 then
  78. newZ = currXYZF[3]
  79. newX = currXYZF[1] - 1
  80. elseif currentOrientation == 3 then
  81. newZ = currXYZF[3] - 1
  82. newX = currXYZF[1]
  83. elseif currentOrientation == 4 then
  84. newZ = currXYZF[3]
  85. newX = currXYZF[1] + 1
  86. end
  87. moveDirection(turtle.forward, turtle.detect, turtle.dig, turtle.attack, maxSupport, newX, currXYZF[2], newZ)
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement