Advertisement
EphemeralKap

Untitled

Dec 4th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 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. if not turtle.up() then
  86. turtle.digUp()
  87. turtle.up()
  88. end
  89. turtle.dig()
  90. end
  91. while true do
  92. local s, d = turtle.inspectDown()
  93. if s and d.name ~= "minecraft:torch" then
  94. turtle.digDown()
  95. turtle.down()
  96. if s and d.name == "minecraft:torch" then
  97. break
  98. end
  99. turtle.down()
  100. end
  101. Replant()
  102. end
  103.  
  104. if side == 1 then
  105. turtle.turnRight()
  106. elseif side == 2 then
  107. turtle.turnLeft()
  108. end
  109. end
  110.  
  111. function Replant()
  112. turtle.select(2)
  113. turtle.place()
  114. end
  115.  
  116. -- main loop
  117. -- reset -> refuel -> pickup fuel -> chop -> deposit
  118. while true do
  119.  
  120. -- first get the turtle back to start
  121. if status == 0 or status == 4 then
  122. print("Updating status..")
  123. UpdateStatus()
  124. end
  125.  
  126. --refuel if needed
  127. if turtle.getFuelLevel() < 5 then
  128. print("Refueling..")
  129. Refuel()
  130. end
  131.  
  132. --grab fuel if at start and needed
  133. if turtle.getItemCount(1) < 16 and status == 1 then
  134. print("Grabbing Fuel..")
  135. GrabFuel()
  136. end
  137.  
  138. -- Ready to begin harvesting
  139. if status == 1 then
  140. status = 2
  141. end
  142.  
  143. --Move forward Once, check for trees on left then right, chop them if it finds any.
  144. if status == 2 then
  145. turtle.forward()
  146. ChopTree(1)
  147. ChopTree(2)
  148. end
  149.  
  150. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement