EphemeralKap

Untitled

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