EphemeralKap

Untitled

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