Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.64 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. reSeed()
  95. end
  96. end
  97. else
  98. print("No Block...")
  99. end
  100.  
  101. end
  102.  
  103. function plantBlock()
  104. print("farmblock function")
  105. local success, data = turtle.inspectDown()
  106. if success==false then
  107. print("Empty plot detected, hoeing and planting")
  108. turtle.digDown()
  109. turtle.suckDown()
  110. turtle.placeDown()
  111.  
  112. else
  113. print("No Block...")
  114. end
  115. local functionBreak = true
  116. print("reSeed function")
  117. while functionBreak do
  118. data = turtle.getItemDetail()
  119. if data == nil then
  120. local currentSlot = turtle.getSelectedSlot()
  121. if currentSlot < 15 then
  122. turtle.select(currentSlot + 1)
  123. else
  124. turtle.select(1)
  125. end
  126.  
  127. else
  128. functionBreak = false
  129. end
  130. end
  131. turtle.placeDown()
  132.  
  133. end
  134.  
  135.  
  136. function detectDirection(currentBlock)
  137. print("Detect direction function")
  138. if (currentBlock.W % 2 ~= 0) then
  139. turtle.turnLeft()
  140. turtle.forward()
  141. turtle.turnLeft()
  142. else
  143.  
  144. turtle.turnRight()
  145. turtle.forward()
  146. turtle.turnRight()
  147. end
  148. end
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157. function main(xy)
  158.  
  159. local success, data = turtle.inspect()
  160. if success then
  161. if data.name == "EnderStorage:enderChest" then
  162. panicCorrection()
  163. end
  164. end
  165.  
  166. print(xy.l)
  167. print(xy.w)
  168. local length = tonumber(xy.l)
  169. local width = tonumber(xy.w)
  170. local currentBlock= {L = 0, W = 0}
  171.  
  172. while currentBlock.W < width do
  173. currentBlock.L = 0
  174. print("Here")
  175. while currentBlock.L < length do
  176. turtle.suckDown()
  177. turtle.forward()
  178. turtle.suckDown()
  179. if xy.bool == true then
  180. plantBlock()
  181. else
  182. farmBlock()
  183. end
  184. currentBlock.L = currentBlock.L + 1
  185. end
  186. detectDirection(currentBlock)
  187. farmBlock()
  188. currentBlock.W = currentBlock.W + 1
  189. end
  190.  
  191. local toggled = true
  192. while toggled do
  193. if (currentBlock.W % 2 ~= 0) then
  194. print("dirt detected")
  195. turtle.turnRight()
  196. forward(width)
  197. toggled=false
  198. turtle.turnLeft()
  199. turtle.forward()
  200. turtle.forward()
  201. else
  202. print("stone detected")
  203. turtle.turnLeft()
  204. forward(length)
  205. turtle.turnLeft()
  206. forward(width)
  207. turtle.forward()
  208. toggled=false
  209. end
  210. end
  211.  
  212. turtle.turnLeft()
  213.  
  214.  
  215.  
  216. turtle.turnRight()
  217. refuel()
  218. turtle.turnRight()
  219. turtle.forward()
  220. xy.bool = false
  221. main(xy)
  222. end
  223.  
  224. function startup()
  225. term.clear()
  226. print("#######################################")
  227. print("#######################################")
  228. print("#######################################")
  229. print("##########Blims Farming Turtle#########")
  230. print("#######################################")
  231. print("#######################################")
  232. print("#######################################")
  233. print("###########ver 1.2-12##################")
  234. print("#######################################")
  235. print("#######################################")
  236. print("#######################################")
  237. print("#######################################")
  238. print("#######################################")
  239. sleep(5)
  240. term.clear()
  241. local time = os.time()
  242. local formattedTime = textutils.formatTime(time, false)
  243. print("Session Time Begin: ".. formattedTime)
  244.  
  245. local xy = {l=0, w=0, bool=false}
  246. print("To begin, we need to specify the dimensions of the mining turtle...")
  247. print("Enter the length of perimeter the turtle is working:")
  248. local length = read()
  249. print("Enter the width of perimeter the turtle is working:")
  250. local width = read()
  251. print("Would you like for the first run to autoplant? (y/n):")
  252. local boole = read()
  253.  
  254. xy.l = tonumber(length)
  255. if boole == "y" then
  256. xy.bool = true
  257. else
  258. xy.bool = false
  259. end
  260. xy.w = tonumber(width)
  261.  
  262. if length == width then
  263. print("This farming turtle will work within a ".. length.. " by ".. width.. " square")
  264. print("The work area of the turtle should look like this in the example square:")
  265. print("P= plant export | T = turtle | E= empty fuel bucket | F= full fuel buckets")
  266. print("######")
  267. print("######")
  268. print("######")
  269. print("######")
  270. print("######")
  271. print("PTE###")
  272. print(" F")
  273. else
  274. print("This farming turtle will work within a ".. length.. " by ".. width.. " rectangle")
  275. print("The work area of the turtle should look like this in the example square:")
  276. print("P= plant export | T = turtle | E= empty fuel bucket | F= full fuel buckets")
  277. print("######")
  278. print("######")
  279. print("######")
  280. print("######")
  281. print("######")
  282. print("PTE###")
  283. print(" F")
  284. end
  285.  
  286. refuel()
  287. print(xy.l)
  288. print(xy.w)
  289. sleep(3)
  290. turtle.forward()
  291. main(xy)
  292. end
  293. startup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement