Advertisement
Aetra

onverra

Jan 19th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.81 KB | None | 0 0
  1. -- Current Version
  2. -- 0.15
  3. -- ChangeLogs
  4. -- 0.10 - Adding Chest Code and Enderchest Not Tested i will soon.
  5. -- 0.11 - Add waiting code for items and compress some code
  6. -- 0.12 - Change: sapling1 > 0 to sapling1 > 1 and sapling2 > 0 to sapling2 > 1 and will accept sapling that was cut
  7. -- 0.13 - Remove: enderchest i will add back when i have time and fix spacing but still have no idea
  8. -- what is making program crash
  9. -- 0.14 - add repeating options
  10. -- 0.15 - fix error that was buggy me for 4 months
  11. -- TODO
  12. -- Other Stuff Named TODO This After Done others
  13. -- And Testing after done with back and fuel programs
  14. -- Fixing Spacing I think i will use tabs for this version 0.11 or 0.12
  15.  
  16. -- Locals Variables
  17. -- Inventory Locals
  18. local fuel = turtle.getItemCount(1)
  19. local fuel1 = turtle.getItemCount(2)
  20. local sapling1 = turtle.getItemCount(3)
  21. local sapling2 = turtle.getItemCount(4)
  22. local treeBlock = turtle.getItemCount(5)
  23. local itemError = 0
  24. local noFuelNeeded = 1
  25. -- Programming Locals
  26. local wide = 0
  27. local long = 0
  28. local wideCount = 0
  29. local longCount = 0
  30. local sideMoveCount = 0
  31. local otherSideMoveCount = 0 -- TODO or not needed later
  32. local upCount = 0
  33. local turtleReachTop = 0
  34. local treeDetect = 0
  35. local facing = 0 -- If turtle is forward then it is 0 if is going back then is 1
  36. local furnace = 0 -- Feature-request TODO
  37. local enderChestOn = 0 -- Feature-request TODO
  38. local x = 0 -- I don't use this only for loop it may be remove later on.
  39. local turtleType = 0
  40. local turtleTimes = 0
  41. local turtleTimesDone = 0
  42.  
  43. -- Local Programs
  44. local function check()
  45. if noFuelNeeded == 0 then
  46. if fuel == 0 and fuel1 == 0 then
  47. print("turtle has no fuel")
  48. print("put fuel in 1st and 2nd slot")
  49. itemError = 1
  50. end
  51. end
  52. if Sapling1 == 0 and Sapling2 == 0 then
  53. print("turtle has no sapling")
  54. print("put Sapling in 3nd and 4nd slot")
  55. itemError = 1
  56. end
  57. if treeBlock == 0 then
  58. print("turtle has no tree block to compair with")
  59. print("Put tree block in slot 5")
  60. itemError = 1
  61. end
  62. if itemError == 1 then
  63. print("Items are missing please try again")
  64. print("turtle will recheck in 5 sec")
  65. sleep(5)
  66. end
  67. end
  68.  
  69. local function reCheck()
  70. fuel = turtle.getItemCount(1)
  71. fuel1 = turtle.getItemCount(2)
  72. sapling1 = turtle.getItemCount(3)
  73. sapling2 = turtle.getItemCount(4)
  74. treeBlock = turtle.getItemCount(5)
  75. itemError = 0
  76. end
  77.  
  78. local function treeDetecter()
  79. turtle.forward()
  80. turtle.select(5)
  81. if turtle.compare() then
  82. turtle.dig()
  83. turtle.forward()
  84. longCount = longCount + 1
  85. treeDetect = 1
  86. else
  87. longCount = longCount + 1
  88. treeDetect = 0
  89. end
  90. end
  91.  
  92. local function treeCutter()
  93. repeat
  94. turtle.select(5)
  95. if turtle.compareUp() then
  96. turtle.digUp()
  97. turtle.up()
  98. turtleReachTop = 0
  99. upCount = upCount + 1
  100. else
  101. turtleReachTop = 1
  102. end
  103. until turtleReachTop == 1
  104. repeat
  105. turtle.down()
  106. upCount = upCount - 1
  107. until upCount == 0
  108. turtle.forward()
  109. turtle.turnLeft()
  110. turtle.turnLeft()
  111. if sapling1 > 1 then
  112. turtle.select(3)
  113. turtle.place()
  114. turtle.select(6)
  115. if turtle.compareTo(3) then
  116. if turtle.getItemCount > 32 then
  117. turtle.transferTo(3, 31)
  118. end
  119. end
  120. sapling1 = turtle.getItemCount(3)
  121. elseif sapling2 > 1 then
  122. turtle.select(4)
  123. turtle.place()
  124. turtle.select(6)
  125. if turtle.compareTo(4) then
  126. if turtle.getItemCount > 32 then
  127. turtle.transferTo(4, 31)
  128. end
  129. end
  130. sapling2 = turtle.getItemCount(4)
  131. else
  132. print("out of saplings")
  133. os.shutdown()
  134. end
  135. turtle.turnLeft()
  136. turtle.turnLeft()
  137. end
  138.  
  139. local function treePlant()
  140. turtle.dig()
  141. turtle.forward()
  142. turtle.forward()
  143. turtle.turnLeft()
  144. turtle.turnLeft()
  145. if sapling1 > 1 then
  146. turtle.select(3)
  147. turtle.place()
  148. turtle.select(6)
  149. if turtle.compareTo(3) then
  150. if turtle.getItemCount > 32 then
  151. turtle.transferTo(3, 31)
  152. end
  153. end
  154. sapling1 = turtle.getItemCount(3)
  155. elseif sapling2 > 1 then
  156. turtle.select(4)
  157. turtle.place()
  158. turtle.select(6)
  159. if turtle.compareTo(4) then
  160. if turtle.getItemCount > 32 then
  161. turtle.transferTo(4, 31)
  162. end
  163. end
  164. sapling2 = turtle.getItemCount(4)
  165. else
  166. print("out of saplings")
  167. os.shutdown()
  168. end
  169. turtle.turnLeft()
  170. turtle.turnLeft()
  171. end
  172.  
  173. local function reFuel()
  174. if noFuelNeeded == 0 then
  175. repeat
  176. if turtle.getFuelLevel() < 100 then
  177. if fuel > 1 then
  178. turtle.select(1)
  179. turtle.refuel(1)
  180. turtle.select(5)
  181. if turtle.compareTo(1) then
  182. if turtle.getItemCount > 32 then
  183. turtle.transferTo(1, 31)
  184. end
  185. end
  186. fuel = turtle.getItemCount(1)
  187. elseif fuel1 > 1 then
  188. turtle.select(2)
  189. turtle.refuel(1)
  190. turtle.select(5)
  191. if turtle.compareTo(2) then
  192. if turtle.getItemCount > 32 then
  193. turtle.transferTo(2, 31)
  194. end
  195. end
  196. fuel1 = turtle.getItemCount(2)
  197. else
  198. print("out of fuel")
  199. os.shutdown()
  200. end
  201. end
  202. until turtle.getFuelLevel() >= 100
  203. end
  204. end
  205.  
  206. local function side()
  207. turtle.forward()
  208. longCount = 0
  209. sideMoveCount = sideMoveCount + 3
  210. if facing == 0 then
  211. turtle.turnRight()
  212. turtle.forward()
  213. turtle.forward()
  214. turtle.forward()
  215. turtle.turnRight()
  216. facing = 1
  217. else --TODO
  218. facing = 0
  219. turtle.turnLeft()
  220. turtle.forward()
  221. turtle.forward()
  222. turtle.forward()
  223. turtle.turnLeft()
  224. end
  225. end
  226.  
  227. local function back() --TODO
  228. if facing == 1 then
  229. turtle.forward()
  230. turtle.turnRight()
  231. repeat
  232. turtle.forward()
  233. sideMoveCount = sideMoveCount - 1
  234. until sideMoveCount == 0
  235. turtle.turnRight()
  236. turtle.back()
  237. else
  238. turtle.forward()
  239. turtle.turnLeft()
  240. repeat
  241. turtle.forward()
  242. sideMoveCount = sideMoveCount - 1
  243. until sideMoveCount == 0
  244. turtle.turnLeft()
  245. turtle.back()
  246. end
  247. end
  248.  
  249. local function chest()
  250. turtle.turnLeft()
  251. turtle.turnLeft()
  252. for slot = 6, 16 do
  253. turtle.select(slot)
  254. sleep(1.0)
  255. turtle.drop()
  256. end
  257. end
  258.  
  259. local function restart()
  260. if turtleType == 0 then
  261. longCount = 0
  262. wideCount = 0
  263. elseif turtleType == 1 then
  264. sleep(180)
  265. longCount = 0
  266. wideCount = 0
  267. elseif turtleType == 2 then
  268. if turtleTimesDone ~= turtleTimes then
  269. turtleTimes = turtleTime + 1
  270. else
  271. print("turtle is Done")
  272. os.shutdown()
  273. end
  274. end
  275. end
  276.  
  277. function start()
  278. turtle.forward()
  279. repeat
  280. repeat
  281. treeDetect = 0
  282. reFuel()
  283. treeDetecter()
  284. if treeDetect == 1 then
  285. treeCutter()
  286. else
  287. treePlant()
  288. end
  289. until long == longCount
  290. wideCount = wideCount + 1
  291. if wide ~= wideCount then
  292. side()
  293. end
  294. until wide == wideCount
  295. back()
  296. chest()
  297. restart()
  298. start()
  299. end
  300.  
  301. -- Starting
  302. print("Welecome to Turtle Tree Logger Program")
  303. print("Fuel in slot 1 & 2, and Sapling in slot 3 & 4, and one piece of wood that you are farming in slot 5")
  304. print("turtle is sleep 10 sec to wait for items")
  305. sleep(10)
  306. fuel = turtle.getItemCount(1)
  307. fuel1 = turtle.getItemCount(2)
  308. sapling1 = turtle.getItemCount(3)
  309. sapling2 = turtle.getItemCount(4)
  310. treeBlock = turtle.getItemCount(5)
  311. print("How long for saplings")
  312. input1 = io.read()
  313. long = tonumber(input1)
  314. print("How wide for Saplings")
  315. input2 = io.read()
  316. wide = tonumber(input2)
  317. print("what type of repeater want to use")
  318. print("0 = is forever but it done wait for 180 sec it useful small tree farms")
  319. print("1 = is forever when it reach end so soon turtle put it item he will start aging")
  320. print("2 = user will choose how many time")
  321. input3 = io.read()
  322. turtleType = tonumber(input3)
  323. if turtleType == 2 then
  324. print("how many times")
  325. input4 = io.read()
  326. turtleTimes = tonumber(input4)
  327. end
  328. print("Turtle go to work")
  329. if turtle.getFuelLevel() == "unlimited" then
  330. print("your turtle configure does not need fuel")
  331. noFuelNeeded = 1
  332. elseif turtle.getFuelLevel() < 100 then
  333. reFuel()
  334. end
  335. check()
  336. if itemError == 1 then
  337. repeat
  338. reCheck()
  339. check()
  340. until itemError == 0
  341. end
  342. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement