Advertisement
visiongaming43

Untitled

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