Advertisement
MrHG

SDChopper v0.5

Aug 4th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. -- uses Robust Turtle API: pastebin get 0TnEBf2P t
  2. os.loadAPI("t")
  3. -- local args = {...}
  4. local versionNumber = "0.5"
  5. local programName = "StarDustChopper"
  6. local programNameShort = "SDChopper"
  7. local startInventory = 3
  8. local treeDistance = 1
  9. local refuelAmount = 80
  10. local saplingName = nil
  11.  
  12. --if #args ~= 1 then
  13. -- print ("Usage: "..programNameShort.." (Amount of Simultanious Trees)")
  14. -- return
  15. --else
  16. -- treeAmount = tonumber(args[1])
  17. -- if treeAmount < 1 then
  18. -- print("Amount Of trees must be positive")
  19. -- return
  20. -- end
  21.  
  22. function Refuel(amountOfRequiredFuel)
  23. turtle.select(1)
  24. if (turtle.getFuelLevel() == "unlimited") then
  25. -- that's pretty neat dude.
  26. return
  27. end
  28. if (turtle.getFuelLevel() < amountOfRequiredFuel) then
  29. while (true) do
  30. if turtle.refuel(1) then
  31. if (turtle.getFuelLevel() > amountOfRequiredFuel) then
  32. break
  33. end
  34. else
  35. print("Turtle could not refuel. Please check why.")
  36. error()
  37. end
  38. end
  39. end
  40. end
  41.  
  42. function CheckSaplings()
  43. turtle.select(2)
  44. if turtle.getItemDetail() then
  45. if saplingName ~= nil then
  46. if turtle.getItemDetail().name == saplingName then
  47. return true
  48. else
  49. print("Foreign object in Sapling Area. Looking for others.")
  50. turtle.transferTo(16)
  51. for i=1,16 do
  52. turtle.select(i)
  53. if turtle.getItemDetail() ~= nil then
  54. if turtle.getItemDetail().name == saplingName then
  55. turtle.transferTo(2)
  56. print("Found others. Continuing.")
  57. return true
  58. end
  59. end
  60. end
  61. print("Could not find more saplings.")
  62. CheckSaplings()
  63. end
  64. else
  65. saplingName = turtle.getItemDetail().name
  66. end
  67. else
  68. print("Please insert saplings. Retrying in 5 Seconds.")
  69. sleep(5)
  70. CheckSaplings()
  71. end
  72. end
  73.  
  74. function CheckIfGrown()
  75. turtle.select(2)
  76. if not turtle.detect() then
  77. CheckSaplings()
  78. t.place(2)
  79. return false
  80. elseif turtle.compare() then
  81. return false
  82. else
  83. return true
  84. end
  85. end
  86.  
  87. function CutTree()
  88. turtle.select(2)
  89. t.dig()
  90. t.forward()
  91. t.digUp()
  92. t.up()
  93. t.digUp()
  94. t.up()
  95. local upCount = 2
  96. while turtle.detectUp() do
  97. t.digUp()
  98. t.up()
  99. upCount = upCount + 1
  100. t.dig()
  101. t.right()
  102. t.dig()
  103. t.right()
  104. t.dig()
  105. t.right()
  106. t.dig()
  107. t.right()
  108. end
  109. t.down(upCount)
  110. t.back()
  111. end
  112.  
  113. function EmptyInventory()
  114. local itemsDepositedCount = 0
  115. for i=startInventory,16 do
  116. turtle.select(i)
  117. itemsDepositedCount = itemsDepositedCount + turtle.getItemCount()
  118. if turtle.getItemCount() == 0 then
  119. --twiddle your thumbs
  120. elseif not turtle.drop() then
  121. print("Container full. Please empty it.")
  122. error()
  123. end
  124. end
  125. print("Deposited "..itemsDepositedCount.." Items.")
  126. end
  127.  
  128. function CheckInventory()
  129. turtle.select(14)
  130. if turtle.getItemCount() > 0 then
  131. t.turnAround()
  132. EmptyInventory()
  133. t.turnAround()
  134. end
  135. end
  136.  
  137. function Farm()
  138. if CheckSaplings() then
  139. if CheckIfGrown() then
  140. CutTree()
  141. if CheckSaplings() then
  142. CheckIfGrown()
  143. end
  144. end
  145. end
  146. end
  147.  
  148. -- INITIAL SETUP FASE
  149. term.clear()
  150. term.setCursorPos(1,1)
  151. print("Welcome to"..programName.."Version "..versionNumber.." !")
  152. print("(Coded by MrHG using RobustTurtleAPI)")
  153. print("")
  154. sleep(1)
  155. print("Insert Fuel in slot 1")
  156. print("Insert Sapling in slot 2")
  157. Refuel(80)
  158. CheckSaplings()
  159. -- Main Block
  160. term.clear()
  161. term.setCursorPos(1,1)
  162. print ("Commence Chopping!")
  163. while true do
  164. -- AT START
  165. CheckInventory()
  166. Refuel(refuelAmount)
  167. Farm()
  168. -- OOO
  169. -- O O
  170. -- OXO
  171. t.strafeRight(treeDistance)
  172. Refuel(refuelAmount)
  173. Farm()
  174. -- OOO
  175. -- O O
  176. -- OOX
  177. t.strafeRight(treeDistance)
  178. t.forward(2)
  179. t.left()
  180. Refuel(refuelAmount)
  181. Farm()
  182. -- OOO
  183. -- O X
  184. -- OOO
  185. t.strafeRight(treeDistance)
  186. Refuel(refuelAmount)
  187. Farm()
  188. -- OOX
  189. -- O O
  190. -- OOO
  191. t.strafeRight(treeDistance)
  192. t.forward(2)
  193. t.left()
  194. Refuel(refuelAmount)
  195. Farm()
  196. -- OXO
  197. -- O O
  198. -- OOO
  199. t.strafeRight(treeDistance)
  200. Refuel(refuelAmount)
  201. Farm()
  202. -- XOO
  203. -- O O
  204. -- OOO
  205. t.strafeRight(treeDistance)
  206. t.forward(2)
  207. t.left()
  208. Refuel(refuelAmount)
  209. Farm()
  210. -- OOO
  211. -- X O
  212. -- OOO
  213. t.strafeRight(treeDistance)
  214. Refuel(refuelAmount)
  215. Farm()
  216. -- OOO
  217. -- O O
  218. -- XOO
  219. t.strafeRight(treeDistance)
  220. t.forward(2)
  221. t.left()
  222. Refuel(refuelAmount)
  223. Farm()
  224. -- OOO
  225. -- O O
  226. -- OXO
  227. if CheckSaplings() then
  228. local timesChecked = 0
  229. while not CheckIfGrown() do
  230. t.turnAround()
  231. t.turnAround()
  232. sleep(10)
  233. timesChecked = timesChecked + 1
  234. if (timesChecked > 30) then
  235. break
  236. end
  237. end
  238. CutTree()
  239. end
  240. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement