EphemeralKap

Untitled

Dec 4th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 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. Replant()
  82. else
  83. return false
  84. end
  85. end
  86.  
  87. function ChopTree(side)
  88. if CheckTree(side) then
  89. turtle.dig()
  90. for i = 1, 5 do
  91. print("Chopping up: " .. i)
  92. if not turtle.up() then
  93. turtle.digUp()
  94. turtle.up()
  95. end
  96. turtle.dig()
  97. end
  98. while true do
  99. sleep(0.1)
  100. local s, d = turtle.inspectDown()
  101. if s and d.name ~= "minecraft:torch" then
  102. print("Going down but leaves in way?")
  103. turtle.digDown()
  104. turtle.down()
  105. end
  106. if s and d.name == "minecraft:torch" then
  107. print("I'm back down now")
  108. break
  109. end
  110. turtle.down()
  111. print("Moving down..")
  112. end
  113. Replant()
  114. end
  115.  
  116. if side == 1 then
  117. turtle.turnRight()
  118. elseif side == 2 then
  119. turtle.turnLeft()
  120. end
  121. end
  122.  
  123. function Replant()
  124. turtle.select(2)
  125. turtle.place()
  126. end
  127.  
  128. function Forward()
  129. turtle.forward()
  130. end
  131.  
  132. -- main loop
  133. -- reset -> refuel -> pickup fuel -> chop -> deposit
  134. while true do
  135. print("Breaking")
  136. -- first get the turtle back to start
  137. if status == 0 or status == 4 then
  138. print("Updating status..")
  139. UpdateStatus()
  140. end
  141.  
  142. --refuel if needed
  143. if turtle.getFuelLevel() < 5 then
  144. print("Refueling..")
  145. Refuel()
  146. end
  147.  
  148. --grab fuel if at start and needed
  149. if turtle.getItemCount(1) < 16 and status == 1 then
  150. print("Grabbing Fuel..")
  151. GrabFuel()
  152. end
  153.  
  154. -- Ready to begin harvesting, dump inventory and load saplings first
  155. if status == 1 then
  156. turtle.turnLeft()
  157. for i = 2,16 do
  158. if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == "minecraft:sapling" then
  159. turtle.select(i)
  160. turtle.drop()
  161. end
  162. end
  163. turtle.suck()
  164. turtle.turnLeft()
  165. for i = 3,16 do
  166. if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == "minecraft:log" then
  167. turtle.select(i)
  168. turtle.drop()
  169. end
  170. end
  171. status = 2
  172. turtle.turnLeft()
  173. turtle.turnLeft()
  174. end
  175.  
  176. --Move forward Once, check for trees on left then right, chop them if it finds any.
  177. if status == 2 then
  178. turtle.forward()
  179. turtle.suckDown()
  180. ChopTree(1)
  181. ChopTree(2)
  182. end
  183.  
  184. end
Advertisement
Add Comment
Please, Sign In to add comment