Advertisement
EphemeralKap

Untitled

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