Advertisement
EphemeralKap

Untitled

Dec 4th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 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.getItemDetail(2).name == "minecraft:sapling" then
  127. turtle.place()
  128. end
  129. end
  130.  
  131. function Forward()
  132. turtle.forward()
  133. end
  134.  
  135. function RefuelIfNeeded()
  136. if turtle.getFuelLevel() < 5 then
  137. print("Refueling..")
  138. Refuel()
  139. end
  140. end
  141.  
  142. -- main loop
  143. -- reset -> refuel -> pickup fuel -> chop -> deposit
  144. while true do
  145. print("Breaking")
  146. -- first get the turtle back to start
  147. if status == 0 or status == 4 then
  148. print("Updating status..")
  149. UpdateStatus()
  150. end
  151.  
  152. --grab fuel if at start and needed
  153. if turtle.getItemCount(1) < 16 and status == 1 then
  154. print("Grabbing Fuel..")
  155. GrabFuel()
  156. end
  157.  
  158. --refuel if needed
  159. RefuelIfNeeded()
  160. -- Ready to begin harvesting, dump inventory and load saplings first
  161. if status == 1 then
  162. turtle.turnLeft()
  163. for i = 2,16 do
  164. if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == "minecraft:sapling" then
  165. turtle.select(i)
  166. turtle.drop()
  167. end
  168. end
  169. turtle.turnLeft()
  170. for i = 3,16 do
  171. if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == "minecraft:log" then
  172. turtle.select(i)
  173. turtle.drop()
  174. end
  175. end
  176. status = 2
  177. turtle.turnRight()
  178. turtle.select(2)
  179. turtle.suck()
  180. turtle.turnRight()
  181. end
  182.  
  183. --Move forward Once, check for trees on left then right, chop them if it finds any.
  184. if status == 2 then
  185. turtle.forward()
  186. RefuelIfNeeded()
  187. local s, d = turtle.inspect()
  188. if s and d.name == "minecraft:gravel" then
  189. status = 4
  190. break
  191. end
  192. turtle.suckDown()
  193. ChopTree(1)
  194. ChopTree(2)
  195. end
  196.  
  197. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement