EphemeralKap

Untitled

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