EphemeralKap

Untitled

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