EphemeralKap

Untitled

Dec 4th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 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. turtle.refuel(3)
  14. end
  15.  
  16. --grabs fuel from coal chest
  17. function GrabFuel()
  18. turtle.turnLeft()
  19. turtle.select(1)
  20. turtle.suck()
  21. turtle.turnRight()
  22. end
  23.  
  24. -- This function checks where the turtle is located on the rail, it's needed in case the program boots while the
  25. -- turtle is not at the start of the dropoff location
  26. function UpdateStatus()
  27. local s, under = turtle.inspectDown()
  28. local s2, front = turtle.inspect()
  29.  
  30.  
  31. lastStatus = status
  32. if s then
  33. if under.name == "minecraft:cobblestone" then
  34. status = 1
  35. end
  36. if under.name == "minecraft:torch" then
  37. status = 4
  38. end
  39. if under.name == "minecraft:dirt" then
  40. turtle.back()
  41. turtle.turnLeft()
  42. end
  43. end --todo: check if on right y level, should be if s is false
  44.  
  45. if s2 then
  46. if front.name == "minecraft:chest" then
  47. turtle.turnLeft()
  48. turtle.turnLeft()
  49. status = 1
  50. end
  51. if front.name == "minecraft:log" or front.name == "minecraft:sapling" then
  52. turtle.turnLeft()
  53. UpdateStatus()
  54. end
  55. if front.name == "minecraft:gravel" then
  56. turtle.turnLeft()
  57. turtle.turnLeft()
  58. end
  59. elseif status == 4 then
  60. turtle.forward()
  61. end
  62.  
  63. print("Updated Status: " .. lastStatus .. " to " .. status)
  64.  
  65. end
  66.  
  67. function CheckTree(side)
  68. if side == 1 then
  69. turtle.turnLeft()
  70. elseif side == 2 then
  71. turtle.turnRight()
  72. end
  73. local s, d = turtle.inspect()
  74. if s and d.name == "minecraft:log" then
  75. return true
  76. else
  77. return false
  78. end
  79. end
  80.  
  81. function ChopTree(side)
  82. if CheckTree(side) then
  83. turtle.dig()
  84. for i = 1, 5 do
  85. print("Chopping up: " .. i)
  86. if not turtle.up() then
  87. turtle.digUp()
  88. turtle.up()
  89. end
  90. turtle.dig()
  91. end
  92. while true do
  93. sleep(0.1)
  94. local s, d = turtle.inspectDown()
  95. if s and d.name ~= "minecraft:torch" then
  96. print("Going down but leaves in way?")
  97. turtle.digDown()
  98. turtle.down()
  99. end
  100. if s and d.name == "minecraft:torch" then
  101. print("I'm back down now")
  102. break
  103. end
  104. turtle.down()
  105. print("Moving down..")
  106. end
  107. Replant()
  108. end
  109.  
  110. if side == 1 then
  111. turtle.turnRight()
  112. elseif side == 2 then
  113. turtle.turnLeft()
  114. end
  115. end
  116.  
  117. function Replant()
  118. turtle.select(2)
  119. turtle.place()
  120. end
  121.  
  122. -- main loop
  123. -- reset -> refuel -> pickup fuel -> chop -> deposit
  124. while true do
  125. print("Breaking")
  126. -- first get the turtle back to start
  127. if status == 0 or status == 4 then
  128. print("Updating status..")
  129. UpdateStatus()
  130. end
  131.  
  132. --refuel if needed
  133. if turtle.getFuelLevel() < 5 then
  134. print("Refueling..")
  135. Refuel()
  136. end
  137.  
  138. --grab fuel if at start and needed
  139. if turtle.getItemCount(1) < 16 and status == 1 then
  140. print("Grabbing Fuel..")
  141. GrabFuel()
  142. end
  143.  
  144. -- Ready to begin harvesting
  145. if status == 1 then
  146. status = 2
  147. end
  148.  
  149. --Move forward Once, check for trees on left then right, chop them if it finds any.
  150. if status == 2 then
  151. turtle.forward()
  152. ChopTree(1)
  153. ChopTree(2)
  154. end
  155.  
  156. end
Advertisement
Add Comment
Please, Sign In to add comment