Advertisement
visiongaming43

Untitled

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