Advertisement
visiongaming43

Untitled

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