Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.63 KB | None | 0 0
  1. --todo:
  2. -- add function that makes sure that seeds are in the two first slots and they are a stack worth if not, will take two stacks from sorted chest
  3. -- add command in farmblock for tilling land for non fertilized
  4.  
  5.  
  6. function refuel()
  7. empty()
  8. print("refueling")
  9. if turtle.getFuelLevel() <= 500 then
  10.  
  11. print("Refueling... amt 1000")
  12. turtle.turnLeft()
  13. turtle.select(3)
  14. turtle.suck()
  15. turtle.refuel()
  16. turtle.turnLeft()
  17. turtle.drop()
  18. turtle.turnLeft()
  19. end
  20. end
  21.  
  22. function panicCorrection()
  23. local panicMode = true
  24. while panicMode do
  25. local success, data = turtle.inspect()
  26. if success then
  27. if data.name == "EnderStorage:enderChest" then
  28. print("SYSTEM PANIC! RECOVERING")
  29. turtle.turnRight()
  30. end
  31. else
  32. print("System Recovered.")
  33. panicMode = false
  34. turtle.forward()
  35. end
  36. end
  37. end
  38.  
  39.  
  40. function forward(amount)
  41. local counter = 0
  42. local amt = tonumber(amount)
  43. print("forward function")
  44. while counter < amt do
  45. turtle.forward()
  46. counter = counter + 1
  47. end
  48. end
  49.  
  50. function empty()
  51. print("Emptying..")
  52. local slots = 3
  53. while slots < 17 do
  54. print("Dropped slot ".. slots)
  55. turtle.select(slots)
  56. turtle.drop()
  57. slots = slots + 1
  58. end
  59. print("Empty COMPLETE")
  60. end
  61.  
  62. function reSeed()
  63. local functionBreak = true
  64. print("reSeed function")
  65. while functionBreak do
  66. local data = turtle.getItemDetail()
  67. if data == nil then
  68. local currentSlot = turtle.getSelectedSlot()
  69. if currentSlot < 15 then
  70. turtle.select(currentSlot + 1)
  71. else
  72. turtle.select(1)
  73. end
  74.  
  75. else
  76. functionBreak = false
  77. end
  78. end
  79. local success, data2 = turtle.inspectDown()
  80. if not success then
  81. turtle.place()
  82. end
  83. end
  84.  
  85.  
  86. function farmBlock()
  87. print("farmblock function")
  88. local success, data = turtle.inspectDown()
  89. if success then
  90. if data.name == "minecraft:carrots" then
  91. if data.metadata == 7 then
  92. print("Adult carrot Detected, Chopping and Cropping")
  93. turtle.digDown()
  94. turtle.suckDown()
  95. reSeed()
  96. end
  97. end
  98. else
  99. print("No Block...")
  100. end
  101.  
  102. end
  103.  
  104. function plantBlock()
  105. print("farmblock function")
  106. local success, data = turtle.inspectDown()
  107. if success==false then
  108. print("Empty plot detected, hoeing and planting")
  109. turtle.digDown()
  110. turtle.suckDown()
  111. turtle.placeDown()
  112.  
  113. else
  114. print("No Block...")
  115. end
  116. local functionBreak = true
  117. print("reSeed function")
  118. while functionBreak do
  119. data = turtle.getItemDetail()
  120. if data == nil then
  121. local currentSlot = turtle.getSelectedSlot()
  122. if currentSlot < 15 then
  123. turtle.select(currentSlot + 1)
  124. else
  125. turtle.select(1)
  126. end
  127.  
  128. else
  129. functionBreak = false
  130. end
  131. end
  132. turtle.placeDown()
  133.  
  134. end
  135.  
  136.  
  137. function detectDirection(currentBlock)
  138. print("Detect direction function")
  139. if (currentBlock.W % 2 ~= 0) then
  140. turtle.turnLeft()
  141. turtle.forward()
  142. turtle.turnLeft()
  143. else
  144.  
  145. turtle.turnRight()
  146. turtle.forward()
  147. turtle.turnRight()
  148. end
  149. end
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. function main(xy)
  159.  
  160. local success, data = turtle.inspect()
  161. if success then
  162. if data.name == "EnderStorage:enderChest" then
  163. panicCorrection()
  164. end
  165. end
  166.  
  167. print(xy.l)
  168. print(xy.w)
  169. local length = tonumber(xy.l)
  170. local width = tonumber(xy.w)
  171. local currentBlock= {L = 0, W = 0}
  172.  
  173. while currentBlock.W < width do
  174. currentBlock.L = 0
  175. print("Here")
  176. while currentBlock.L < length do
  177. turtle.forward()
  178. if xy.bool == true then
  179. plantBlock()
  180. else
  181. farmBlock()
  182. end
  183. currentBlock.L = currentBlock.L + 1
  184. end
  185. detectDirection(currentBlock)
  186. farmBlock()
  187. currentBlock.W = currentBlock.W + 1
  188. end
  189.  
  190. local toggled = true
  191. while toggled do
  192. if (currentBlock.W % 2 ~= 0) then
  193. print("dirt detected")
  194. turtle.turnRight()
  195. forward(width)
  196. toggled=false
  197. turtle.turnLeft()
  198. turtle.forward()
  199. turtle.forward()
  200. else
  201. print("stone detected")
  202. turtle.turnLeft()
  203. forward(length)
  204. turtle.turnLeft()
  205. forward(width)
  206. turtle.forward()
  207. toggled=false
  208. end
  209. end
  210.  
  211. turtle.turnLeft()
  212.  
  213.  
  214.  
  215. turtle.turnRight()
  216. refuel()
  217. turtle.turnRight()
  218. turtle.forward()
  219. xy.bool = false
  220. main(xy)
  221. end
  222.  
  223. function startup()
  224. term.clear()
  225. print("#######################################")
  226. print("#######################################")
  227. print("#######################################")
  228. print("##########Blims Farming Turtle#########")
  229. print("#######################################")
  230. print("#######################################")
  231. print("#######################################")
  232. print("###########ver 1.2-12##################")
  233. print("#######################################")
  234. print("#######################################")
  235. print("#######################################")
  236. print("#######################################")
  237. print("#######################################")
  238. sleep(5)
  239. term.clear()
  240. local time = os.time()
  241. local formattedTime = textutils.formatTime(time, false)
  242. print("Session Time Begin: ".. formattedTime)
  243.  
  244. local xy = {l=0, w=0, bool=false}
  245. print("To begin, we need to specify the dimensions of the mining turtle...")
  246. print("Enter the length of perimeter the turtle is working:")
  247. local length = read()
  248. print("Enter the width of perimeter the turtle is working:")
  249. local width = read()
  250. print("Would you like for the first run to autoplant? (y/n):")
  251. local boole = read()
  252.  
  253. xy.l = tonumber(length)
  254. if boole == "y" then
  255. xy.bool = true
  256. else
  257. xy.bool = false
  258. end
  259. xy.w = tonumber(width)
  260.  
  261. if length == width then
  262. print("This farming turtle will work within a ".. length.. " by ".. width.. " square")
  263. print("The work area of the turtle should look like this in the example square:")
  264. print("P= plant export | T = turtle | E= empty fuel bucket | F= full fuel buckets")
  265. print("######")
  266. print("######")
  267. print("######")
  268. print("######")
  269. print("######")
  270. print("PTE###")
  271. print(" F")
  272. else
  273. print("This farming turtle will work within a ".. length.. " by ".. width.. " rectangle")
  274. print("The work area of the turtle should look like this in the example square:")
  275. print("P= plant export | T = turtle | E= empty fuel bucket | F= full fuel buckets")
  276. print("######")
  277. print("######")
  278. print("######")
  279. print("######")
  280. print("######")
  281. print("PTE###")
  282. print(" F")
  283. end
  284.  
  285. refuel()
  286. print(xy.l)
  287. print(xy.w)
  288. sleep(3)
  289. turtle.forward()
  290. main(xy)
  291. end
  292. startup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement