Advertisement
EphemeralKap

Untitled

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