Advertisement
visiongaming43

Untitled

Sep 19th, 2021
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.71 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. turtle.goDown()
  52. seedIndex = getSeedIndex()
  53. if(seedIndex ~= nil) then
  54. turtle.select(seedIndex)
  55. turtle.placeDown()
  56. end
  57. turtle.goUp()
  58. end
  59. end
  60.  
  61. if(fuelLevel > fuelNeeded) then
  62. for a = length, 1, -1
  63. do
  64. direction = not(direction)
  65. turtle.forward()
  66. getCrop()
  67.  
  68. if(direction) then
  69. turtle.turnLeft()
  70. else
  71. turtle.turnRight()
  72. end
  73.  
  74. for b = width-1, 1, -1
  75. do
  76. turtle.forward()
  77. getCrop()
  78. end
  79.  
  80. if(direction) then
  81. turtle.turnRight()
  82. else
  83. turtle.turnLeft()
  84. end
  85. end
  86.  
  87. -- Getting turtles NEW GPS coordinates
  88. local x2, y2, z2 = gps.locate()
  89.  
  90. -- If the new x-coord is less than the first, then go West (vice versa)
  91.  
  92. if x2 < x1 then
  93. goEast = true
  94. goWest = false
  95. elseif x2 > x1 then
  96. goWest = true
  97. goEast = false
  98. else
  99. goEast = false
  100. goWest = false
  101. end
  102.  
  103. -- If the new y-coord is less than the first, then go Up (vice versa)
  104.  
  105. if y2 < y1 then
  106. goUp = true
  107. goDown = false
  108. elseif y2 > y1 then
  109. goDown = true
  110. goUp = false
  111. else
  112. goDown = false
  113. goUp = false
  114. end
  115.  
  116. -- If the new z-coord is less than the first, then go North (vice versa)
  117.  
  118. if z2 < z1 then
  119. goSouth = true
  120. goNorth = false
  121. elseif z2 > z1 then
  122. goNorth = true
  123. goSouth = false
  124. else
  125. goSouth = false
  126. goNorth = false
  127. end
  128.  
  129. -- Move forward ONCE
  130.  
  131. turtle.forward()
  132.  
  133. -- Refresh GPS location (for calibrating direction of turtle)
  134.  
  135. local x3, y3, z3 = gps.locate()
  136.  
  137. -- If the turtle's x-coordinate gets bigger, it is facing East (vice versa)
  138.  
  139. if x3 > x2 then
  140. faceEast = true
  141. faceWest = false
  142. faceNorth = false
  143. faceSouth = false
  144. elseif x3 < x2 then
  145. faceWest = true
  146. faceEast = false
  147. faceNorth = false
  148. faceSouth = false
  149. end
  150.  
  151. -- If the turtle's z-coordinate gets bigger, it is facing South (vice versa)
  152.  
  153. if z3 > z2 then
  154. faceSouth = true
  155. faceNorth = false
  156. faceEast = false
  157. faceWest = false
  158. elseif z3 < z2 then
  159. faceNorth = true
  160. faceSouth = false
  161. faceEast = false
  162. faceWest = false
  163. end
  164.  
  165. -- Match z-coords to the beginning position
  166. if ((faceNorth == true and goNorth == true) or (faceSouth == true and goSouth == true)) then
  167. for a = math.abs(z3 - z1), 1, -1
  168. do
  169. while turtle.detect() == true
  170. do
  171. turtle.dig()
  172. end
  173. turtle.forward()
  174. end
  175. end
  176. if ((faceNorth == true and goSouth == true) or (faceSouth == true and goNorth == true)) then
  177. turtle.turnRight()
  178. turtle.turnRight()
  179.  
  180. for b = math.abs(z3 - z1), 1, -1
  181. do
  182. while turtle.detect() == true
  183. do
  184. turtle.dig()
  185. end
  186. turtle.forward()
  187. end
  188. end
  189.  
  190. -- Match x-coords to the beginning position
  191. if ((faceEast == true and goEast == true) or (faceWest == true and goWest == true)) then
  192. for c = math.abs(x3 - x1), 1, -1
  193. do
  194. while turtle.detect() == true
  195. do
  196. turtle.dig()
  197. end
  198. turtle.forward()
  199. end
  200. end
  201. if ((faceEast == true and goWest == true) or (faceWest == true and goEast == true)) then
  202. turtle.turnRight()
  203. turtle.turnRight()
  204.  
  205. for d = math.abs(x3 - x1), 1, -1
  206. do
  207. while turtle.detect() == true
  208. do
  209. turtle.dig()
  210. end
  211. turtle.forward()()
  212. end
  213. end
  214.  
  215. -- Match y-coords to the beginning position
  216. if (goUp == true) then
  217. for e = math.abs(y3 - y1), 1, -1
  218. do
  219. while turtle.detectUp() == true
  220. do
  221. turtle.digUp()
  222. end
  223. turtle.Up()
  224. end
  225. end
  226. if (goDown == true) then
  227. for f = math.abs(y3 - y1), 1, -1
  228. do
  229. while turtle.detectDown() == true
  230. do
  231. turtle.digDown()
  232. end
  233. turtle.Down()
  234. end
  235. end
  236.  
  237. -- Drops ALL the items gained from farming ( seeds and crops ) into chest below starting point
  238. for a = 1, 16, 1
  239. do
  240. turtle.select(a)
  241. turtle.dropDown(64)
  242. end
  243.  
  244. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement