EphemeralKap

Untitled

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