Advertisement
EphemeralKap

Untitled

Dec 4th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. local lastStatus = 0
  2. local status = 0 -- 0Clueless-1Starting-2Harvesting-3Returning-4onRail
  3. local n = 0
  4.  
  5. --todo: if no fuel in fuelslot, return immediatly.
  6.  
  7. -- refuel the turtle with slot 1, coal
  8. function Refuel()
  9. turtle.select(1)
  10. if not turtle.refuel(3) then
  11. status = 3
  12. end
  13. end
  14.  
  15. --grabs fuel from coal chest
  16. function GrabFuel()
  17. turtle.turnLeft()
  18. turtle.select(1)
  19. turtle.suck()
  20. turtle.turnRight()
  21. end
  22.  
  23. -- This function checks where the turtle is located on the rail, it's needed in case the program boots while the
  24. -- turtle is not at the dropoff location
  25. function UpdateStatus()
  26. local s, under = turtle.inspectDown()
  27. local s2, front = turtle.inspect()
  28.  
  29.  
  30. lastStatus = status
  31. if s then
  32. if under.name == "minecraft:cobblestone" then
  33. status = 1
  34. end
  35. if under.name == "minecraft:torch" then
  36. status = 4
  37. end
  38. if under.name == "minecraft:dirt" then
  39. turtle.back()
  40. turtle.turnLeft()
  41. end
  42. if under.name == "minecraft:leaves" then
  43. turtle.digDown()
  44. turtle.down()
  45. end
  46. else
  47. turtle.down()
  48. end
  49.  
  50. if s2 then
  51. if front.name == "minecraft:chest" then
  52. turtle.turnLeft()
  53. turtle.turnLeft()
  54. status = 1
  55. end
  56. if front.name == "minecraft:log" or front.name == "minecraft:sapling" then
  57. turtle.turnLeft()
  58. UpdateStatus()
  59. end
  60. if front.name == "minecraft:gravel" then
  61. turtle.turnLeft()
  62. turtle.turnLeft()
  63. end
  64. elseif status == 4 then
  65. turtle.forward()
  66. end
  67.  
  68. print("Updated Status: " .. lastStatus .. " to " .. status)
  69.  
  70. end
  71.  
  72. function CheckTree(side)
  73. if side == 1 then
  74. turtle.turnLeft()
  75. turtle.suck()
  76. elseif side == 2 then
  77. turtle.turnRight()
  78. turtle.suck()
  79. end
  80. local s, d = turtle.inspect()
  81. if s and d.name == "minecraft:log" then
  82. return true
  83. elseif s and d.name == "minecraft:sapling" then
  84. return false
  85. else
  86. Replant()
  87. return false
  88. end
  89. end
  90.  
  91. function ChopTree(side)
  92. if CheckTree(side) then
  93. turtle.dig()
  94. for i = 1, 4 do
  95. print("Chopping up: " .. i)
  96. if not turtle.up() then
  97. turtle.digUp()
  98. turtle.up()
  99. end
  100. turtle.dig()
  101. end
  102. while true do
  103. sleep(0.1)
  104. local s, d = turtle.inspectDown()
  105. if s and d.name ~= "minecraft:torch" then
  106. print("Going down but leaves in way?")
  107. turtle.digDown()
  108. turtle.down()
  109. end
  110. if s and d.name == "minecraft:torch" then
  111. print("I'm back down now")
  112. break
  113. end
  114. turtle.down()
  115. print("Moving down..")
  116. end
  117. Replant()
  118. end
  119.  
  120. if side == 1 then
  121. turtle.turnRight()
  122. elseif side == 2 then
  123. turtle.turnLeft()
  124. end
  125. end
  126.  
  127. function Replant()
  128. turtle.select(2)
  129. if turtle.getItemCount(2) > 0 then
  130. if turtle.getItemDetail(2).name == "minecraft:sapling" then
  131. turtle.place()
  132. end
  133. end
  134. end
  135.  
  136. function Forward()
  137. turtle.forward()
  138. end
  139.  
  140. function RefuelIfNeeded()
  141. if turtle.getFuelLevel() < 10 then
  142. print("Refueling..")
  143. Refuel()
  144. end
  145. end
  146.  
  147. -- main loop
  148. -- reset -> refuel -> pickup fuel -> chop -> deposit
  149. while true do
  150. -- first get the turtle back to start
  151. if status == 0 or status == 4 then
  152. print("Updating status..")
  153. UpdateStatus()
  154. end
  155.  
  156. --todo, put item in right chest
  157. if turtle.getItemCount(1) > 0 then
  158. if turtle.getItemDetail(1).name ~= "minecraft:coal" then
  159. turtle.select(1)
  160. turtle.dropDown()
  161. end
  162. end
  163.  
  164. --grab fuel if at start
  165. if turtle.getItemCount(1) < 16 and status == 1 then
  166. print("Grabbing Fuel..")
  167. GrabFuel()
  168. end
  169.  
  170. --refuel if needed
  171. RefuelIfNeeded()
  172. -- Ready to begin harvesting, dump inventory and load saplings first
  173. if status == 1 then
  174. turtle.turnRight()
  175. print("Now dumping saplings")
  176. for i = 1,16 do
  177. if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == "minecraft:sapling" then
  178. turtle.select(i)
  179. turtle.drop()
  180. end
  181. end
  182. turtle.turnRight()
  183. print("Now dumping logs")
  184. for i = 1,16 do
  185. if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == "minecraft:log" then
  186. turtle.select(i)
  187. turtle.drop()
  188. end
  189. end
  190. print("Now dumping apples")
  191. for i = 1,16 do
  192. if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == "minecraft:apple" then
  193. turtle.select(i)
  194. turtle.dropUp()
  195. end
  196. end
  197. status = 2
  198. turtle.turnLeft()
  199. turtle.select(2)
  200. turtle.suck()
  201. turtle.turnLeft()
  202. end
  203.  
  204. if n == 2 then
  205. n = 0
  206. sleep(30)
  207. end
  208.  
  209. --Move forward Once, check for trees on left then right, chop them if it finds any.
  210. if status == 2 then
  211. turtle.forward()
  212. RefuelIfNeeded()
  213. local s, d = turtle.inspect()
  214. if s and d.name == "minecraft:gravel" then
  215. n = n + 1
  216. status = 4
  217. end
  218. turtle.suckDown()
  219. ChopTree(1)
  220. ChopTree(2)
  221. end
  222.  
  223. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement