Advertisement
EphemeralKap

Untitled

Dec 4th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 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. end --todo: check if on right y level, should be if s is false
  46.  
  47. if s2 then
  48. if front.name == "minecraft:chest" then
  49. turtle.turnLeft()
  50. turtle.turnLeft()
  51. status = 1
  52. end
  53. if front.name == "minecraft:log" or front.name == "minecraft:sapling" then
  54. turtle.turnLeft()
  55. UpdateStatus()
  56. end
  57. if front.name == "minecraft:gravel" then
  58. turtle.turnLeft()
  59. turtle.turnLeft()
  60. end
  61. elseif status == 4 then
  62. turtle.forward()
  63. end
  64.  
  65. print("Updated Status: " .. lastStatus .. " to " .. status)
  66.  
  67. end
  68.  
  69. function CheckTree(side)
  70. if side == 1 then
  71. turtle.turnLeft()
  72. turtle.suck()
  73. elseif side == 2 then
  74. turtle.turnRight()
  75. turtle.suck()
  76. end
  77. local s, d = turtle.inspect()
  78. if s and d.name == "minecraft:log" then
  79. return true
  80. elseif s and d.name == "minecraft:sapling" then
  81. return false
  82. else
  83. Replant()
  84. return false
  85. end
  86. end
  87.  
  88. function ChopTree(side)
  89. if CheckTree(side) then
  90. turtle.dig()
  91. for i = 1, 5 do
  92. print("Chopping up: " .. i)
  93. if not turtle.up() then
  94. turtle.digUp()
  95. turtle.up()
  96. end
  97. turtle.dig()
  98. end
  99. while true do
  100. sleep(0.1)
  101. local s, d = turtle.inspectDown()
  102. if s and d.name ~= "minecraft:torch" then
  103. print("Going down but leaves in way?")
  104. turtle.digDown()
  105. turtle.down()
  106. end
  107. if s and d.name == "minecraft:torch" then
  108. print("I'm back down now")
  109. break
  110. end
  111. turtle.down()
  112. print("Moving down..")
  113. end
  114. Replant()
  115. end
  116.  
  117. if side == 1 then
  118. turtle.turnRight()
  119. elseif side == 2 then
  120. turtle.turnLeft()
  121. end
  122. end
  123.  
  124. function Replant()
  125. turtle.select(2)
  126. if turtle.getItemCount(2) > 0 then
  127. if turtle.getItemDetail(2).name == "minecraft:sapling" then
  128. turtle.place()
  129. end
  130. end
  131. end
  132.  
  133. function Forward()
  134. turtle.forward()
  135. end
  136.  
  137. function RefuelIfNeeded()
  138. if turtle.getFuelLevel() < 5 then
  139. print("Refueling..")
  140. Refuel()
  141. end
  142. end
  143.  
  144. -- main loop
  145. -- reset -> refuel -> pickup fuel -> chop -> deposit
  146. while true do
  147. print("Breaking")
  148. -- first get the turtle back to start
  149. if status == 0 or status == 4 then
  150. print("Updating status..")
  151. UpdateStatus()
  152. end
  153.  
  154. --grab fuel if at start and needed
  155. if turtle.getItemCount(1) < 16 and status == 1 then
  156. print("Grabbing Fuel..")
  157. GrabFuel()
  158. end
  159.  
  160. --refuel if needed
  161. RefuelIfNeeded()
  162. -- Ready to begin harvesting, dump inventory and load saplings first
  163. if status == 1 then
  164. turtle.turnRight()
  165. print("Now dumping saplings")
  166. for i = 2,16 do
  167. if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == "minecraft:sapling" then
  168. turtle.select(i)
  169. turtle.drop()
  170. end
  171. end
  172. turtle.turnRight()
  173. print("Now dumping logs")
  174. for i = 3,16 do
  175. if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == "minecraft:log" then
  176. turtle.select(i)
  177. turtle.drop()
  178. end
  179. end
  180. status = 2
  181. turtle.turnLeft()
  182. turtle.select(2)
  183. turtle.suck()
  184. turtle.turnLeft()
  185. end
  186.  
  187. --Move forward Once, check for trees on left then right, chop them if it finds any.
  188. if status == 2 then
  189. turtle.forward()
  190. RefuelIfNeeded()
  191. local s, d = turtle.inspect()
  192. if s and d.name == "minecraft:gravel" then
  193. status = 4
  194. break
  195. end
  196. turtle.suckDown()
  197. ChopTree(1)
  198. ChopTree(2)
  199. end
  200.  
  201. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement