Advertisement
visiongaming43

Untitled

Sep 19th, 2021
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.66 KB | None | 0 0
  1. ---@diagnostic disable: lowercase-global
  2. -- Getting fuel level
  3. local fuelLevel = turtle.getFuelLevel()
  4.  
  5. -- Getting GPS coordinates
  6. local x1, y1, z1 = gps.locate()
  7.  
  8. -- Asking user for length and width
  9. print("How far do you want the turtle to go in front")
  10. local length = io.read()
  11.  
  12. print("How far do you want the turtle to go to the side")
  13. local width = io.read()
  14.  
  15. -- Asking for direction
  16. print("Would you like the turtle to go left (after it moves one forward) ONLY TYPE 'True' OR 'False'")
  17. local direction = io.read()
  18.  
  19. -- Getting fuel needed
  20. local fuelNeeded = (length*width) + 1 + (1/2*length) + (1/2*width)
  21.  
  22. -- Making function to get the slot index of the seed
  23. local function getSeedIndex()
  24. for slot = 1, 16, 1 do
  25. local item = turtle.getItemDetail(slot)
  26. if (item ~= nil) then
  27. if (string.match(item.name, "seed")) then
  28. return slot
  29. end
  30. end
  31. end
  32. end
  33.  
  34. -- Making function to take crops
  35. local function getCrop()
  36. local isBlock, data = turtle.inspectDown()
  37. if(isBlock)then
  38. if (string.match(data.name, "croptopia:") and data['state']['age'] == 7) then
  39. turtle.digDown()
  40. for i = 6, 1, -1
  41. do
  42. turtle.suckDown()
  43. seedIndex = getSeedIndex()
  44. if(seedIndex ~= nil) then
  45. turtle.select(seedIndex)
  46. turtle.placeDown()
  47. end
  48. end
  49. end
  50. else
  51. seedIndex = getSeedIndex()
  52. if(seedIndex ~= nil) then
  53. turtle.select(seedIndex)
  54. turtle.placeDown()
  55. end
  56. end
  57. end
  58.  
  59. if(fuelLevel > fuelNeeded) then
  60. for a = length, 1, -1
  61. do
  62. direction = not(direction)
  63. turtle.forward()
  64. getCrop()
  65.  
  66. if(direction) then
  67. turtle.turnLeft()
  68. else
  69. turtle.turnRight()
  70. end
  71.  
  72. for b = width-1, 1, -1
  73. do
  74. turtle.forward()
  75. getCrop()
  76. end
  77.  
  78. if(direction) then
  79. turtle.turnRight()
  80. else
  81. turtle.turnLeft()
  82. end
  83. end
  84.  
  85. -- Getting turtles NEW GPS coordinates
  86. local x2, y2, z2 = gps.locate()
  87.  
  88. -- If the new x-coord is less than the first, then go West (vice versa)
  89.  
  90. if x2 < x1 then
  91. goEast = true
  92. goWest = false
  93. elseif x2 > x1 then
  94. goWest = true
  95. goEast = false
  96. else
  97. goEast = false
  98. goWest = false
  99. end
  100.  
  101. -- If the new y-coord is less than the first, then go Up (vice versa)
  102.  
  103. if y2 < y1 then
  104. goUp = true
  105. goDown = false
  106. elseif y2 > y1 then
  107. goDown = true
  108. goUp = false
  109. else
  110. goDown = false
  111. goUp = false
  112. end
  113.  
  114. -- If the new z-coord is less than the first, then go North (vice versa)
  115.  
  116. if z2 < z1 then
  117. goSouth = true
  118. goNorth = false
  119. elseif z2 > z1 then
  120. goNorth = true
  121. goSouth = false
  122. else
  123. goSouth = false
  124. goNorth = false
  125. end
  126.  
  127. -- Move forward ONCE
  128.  
  129. turtle.forward()
  130.  
  131. -- Refresh GPS location (for calibrating direction of turtle)
  132.  
  133. local x3, y3, z3 = gps.locate()
  134.  
  135. -- If the turtle's x-coordinate gets bigger, it is facing East (vice versa)
  136.  
  137. if x3 > x2 then
  138. faceEast = true
  139. faceWest = false
  140. faceNorth = false
  141. faceSouth = false
  142. elseif x3 < x2 then
  143. faceWest = true
  144. faceEast = false
  145. faceNorth = false
  146. faceSouth = false
  147. end
  148.  
  149. -- If the turtle's z-coordinate gets bigger, it is facing South (vice versa)
  150.  
  151. if z3 > z2 then
  152. faceSouth = true
  153. faceNorth = false
  154. faceEast = false
  155. faceWest = false
  156. elseif z3 < z2 then
  157. faceNorth = true
  158. faceSouth = false
  159. faceEast = false
  160. faceWest = false
  161. end
  162.  
  163. -- Match z-coords to the beginning position
  164. if ((faceNorth == true and goNorth == true) or (faceSouth == true and goSouth == true)) then
  165. for a = math.abs(z3 - z1), 1, -1
  166. do
  167. while turtle.detect() == true
  168. do
  169. turtle.dig()
  170. end
  171. turtle.forward()
  172. end
  173. end
  174. if ((faceNorth == true and goSouth == true) or (faceSouth == true and goNorth == true)) then
  175. turtle.turnRight()
  176. turtle.turnRight()
  177.  
  178. for b = math.abs(z3 - z1), 1, -1
  179. do
  180. while turtle.detect() == true
  181. do
  182. turtle.dig()
  183. end
  184. turtle.forward()
  185. end
  186. end
  187.  
  188. -- Match x-coords to the beginning position
  189. if ((faceEast == true and goEast == true) or (faceWest == true and goWest == true)) then
  190. for c = math.abs(x3 - x1), 1, -1
  191. do
  192. while turtle.detect() == true
  193. do
  194. turtle.dig()
  195. end
  196. turtle.forward()
  197. end
  198. end
  199. if ((faceEast == true and goWest == true) or (faceWest == true and goEast == true)) then
  200. turtle.turnRight()
  201. turtle.turnRight()
  202.  
  203. for d = math.abs(x3 - x1), 1, -1
  204. do
  205. while turtle.detect() == true
  206. do
  207. turtle.dig()
  208. end
  209. turtle.forward()()
  210. end
  211. end
  212.  
  213. -- Match y-coords to the beginning position
  214. if (goUp == true) then
  215. for e = math.abs(y3 - y1), 1, -1
  216. do
  217. while turtle.detectUp() == true
  218. do
  219. turtle.digUp()
  220. end
  221. turtle.Up()
  222. end
  223. end
  224. if (goDown == true) then
  225. for f = math.abs(y3 - y1), 1, -1
  226. do
  227. while turtle.detectDown() == true
  228. do
  229. turtle.digDown()
  230. end
  231. turtle.Down()
  232. end
  233. end
  234.  
  235. -- Drops ALL the items gained from farming ( seeds and crops ) into chest below starting point
  236. for a = 1, 16, 1
  237. do
  238. turtle.select(a)
  239. turtle.dropDown(64)
  240. end
  241.  
  242. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement