Advertisement
bool15

Untitled

Jul 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --=======================================Standard Lbrary=====================================--
  2. function smartFuel()
  3. if turtle.getFuelLevel() <= 0 then
  4. onSlot = turtle.getSelectedSlot()
  5. while not turtle.refuel(1) do
  6.  
  7. onSlot = onSlot + 1
  8. if onSlot == 17 then
  9. onSlot = 1
  10. end
  11. turtle.select(onSlot)
  12. end
  13. end
  14. end
  15.  
  16. function smartFor()
  17. while not turtle.forward() do
  18. turtle.attack()
  19. turtle.dig()
  20. smartFuel()
  21. end
  22. end
  23.  
  24. function smartUp()
  25. while not turtle.up() do
  26. turtle.attackUp()
  27. turtle.digUp()
  28. smartFuel()
  29. end
  30. end
  31.  
  32. function smartDown()
  33. while not turtle.down() do
  34. turtle.attackDown()
  35. turtle.digDown()
  36. smartFuel()
  37. end
  38. end
  39.  
  40. function smartMove(dir)
  41. if dir == -1 then
  42. turtle.turnLeft()
  43. smartFor()
  44. elseif dir == 1 then
  45. turtle.turnRight()
  46. smartFor()
  47. elseif dir == 2 then
  48. smartFor()
  49. elseif dir == -2 then
  50. turtle.turnRight()
  51. turtle.turnRight()
  52. smartFor()
  53. elseif dir == 3 then
  54. smartUp()
  55. elseif dir == -3 then
  56. smartDown()
  57. end
  58. end
  59. --=======================================CoodLibrary==========================-
  60. --start with "initCoords
  61. --====initCoords=====--
  62. function initCoords()
  63. x = 0
  64. y = 0
  65. z = 0
  66. --0 is forwards, 1 is left, goes clockwise to 3
  67. facing = 0
  68.  
  69. --used to remember location before returning to origin
  70. tempX = 0
  71. tempY = 0
  72. tempZ = 0
  73. tempFacing = 0
  74. end
  75.  
  76. function trackedFor()
  77. smartFor()
  78. if facing == 0 then
  79. y = y+1
  80. elseif facing == 1 then
  81. x = x+1
  82. elseif facing == 2 then
  83. y = y-1
  84. elseif facing == 3 then
  85. x = x-1
  86. end
  87. end
  88.  
  89. function trackedUp()
  90. smartUp()
  91. z = z+1
  92. end
  93.  
  94. function trackedDown()
  95. smartDown()
  96. z = z-1
  97. end
  98.  
  99. function trackedRight()
  100. changeFacing(1)
  101. turtle.turnRight()
  102. end
  103.  
  104. function trackedLeft()
  105. changeFacing(-1)
  106. turtle.turnLeft()
  107. end
  108. function trackedMove(dir)
  109. if dir == -1 then
  110. trackedLeft()
  111. trackedFor()
  112. elseif dir == 1 then
  113. trackedRight()
  114. trackedFor()
  115. elseif dir == 2 then
  116. trackedFor()
  117. elseif dir == -2 then
  118. trackedRight()
  119. trackedRight()
  120. trackedFor()
  121. elseif dir == 3 then
  122. trackedUp()
  123. elseif dir == -3 then
  124. trackedDown()
  125. end
  126. end
  127.  
  128. function changeFacing(change)
  129. facing = facing + change
  130. facing = facing % 4
  131. end
  132.  
  133. function face(targetFacing)
  134. while facing ~= targetFacing do
  135. turtle.turnRight()
  136. changeFacing(1)
  137.  
  138. end
  139. end
  140.  
  141. function toCoords(tarX,tarY,tarZ,tarFace)
  142.  
  143.  
  144. if z > tarZ then
  145. for i=tarZ+1,z do
  146. trackedMove(-3)
  147. end
  148. elseif z < tarZ then
  149. for i=z,tarZ-1 do
  150. trackedMove(3)
  151. end
  152. end
  153.  
  154. if y > tarY then
  155. face(2)
  156. for i=tarY+1,y do
  157. trackedMove(2)
  158. end
  159. elseif y < tarY then
  160. face(0)
  161. for i=y,tarY-1 do
  162. trackedMove(2)
  163. end
  164. end
  165.  
  166. if x > tarX then
  167. face(3)
  168. for i=tarX+1,x do
  169. trackedMove(2)
  170. end
  171. elseif x < tarX then
  172. face(1)
  173. for i=x,tarX-1 do
  174. trackedMove(2)
  175. end
  176. end
  177.  
  178. face(tarFace)
  179.  
  180. end
  181.  
  182. function saveCoords()
  183. tempX = x
  184. tempY = y
  185. tempZ = z
  186. tempFacing = facing
  187. end
  188.  
  189. function toSavedCoords()
  190. toCoords(tempX,tempY,tempZ,tempFacing)
  191. end
  192.  
  193. --============================Function Start=============================--
  194. initCoords()
  195. toCoords(2,2,2,0)
  196. saveCoords()
  197. toCoords(0,0,0,0)
  198. toSavedCoords()
  199. print(x .. " " .. y .. " " .. z .. " " ..facing)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement