Advertisement
visiongaming43

Untitled

Sep 19th, 2021
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 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. turtle.forward()
  168. end
  169. end
  170. if ((faceNorth == true and goSouth == true) or (faceSouth == true and goNorth == true)) then
  171. turtle.turnRight()
  172. turtle.turnRight()
  173.  
  174. for b = math.abs(z3 - z1), 1, -1
  175. do
  176. turtle.forward()
  177. end
  178. end
  179.  
  180. -- Match x-coords to the beginning position
  181. if ((faceEast == true and goEast == true) or (faceWest == true and goWest == true)) then
  182. for c = math.abs(x3 - x1), 1, -1
  183. do
  184. turtle.forward()
  185. end
  186. end
  187. if ((faceEast == true and goWest == true) or (faceWest == true and goEast == true)) then
  188. turtle.turnRight()
  189. turtle.turnRight()
  190.  
  191. for d = math.abs(x3 - x1), 1, -1
  192. do
  193. turtle.forward()
  194. end
  195. end
  196.  
  197. -- Match y-coords to the beginning position
  198. if (goUp == true) then
  199. for e = math.abs(y3 - y1), 1, -1
  200. do
  201. turtle.Up()
  202. end
  203. end
  204. if (goDown == true) then
  205. for f = math.abs(y3 - y1), 1, -1
  206. do
  207. turtle.Down()
  208. end
  209. end
  210.  
  211. -- Drops ALL the items gained from farming ( seeds and crops ) into chest below starting point
  212. for a = 1, 16, 1
  213. do
  214. turtle.select(a)
  215. turtle.dropDown(64)
  216. end
  217.  
  218. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement