Advertisement
visiongaming43

Untitled

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