Advertisement
EphemeralKap

Untitled

Dec 4th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 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. end
  34.  
  35. -- This function checks where the turtle is located on the rail, it's needed in case the program boots while the
  36. -- turtle is not at the start of the dropoff location
  37. function UpdateStatus()
  38. local s, under = turtle.inspectDown()
  39. local s2, front = turtle.inspect()
  40.  
  41.  
  42. lastStatus = status
  43. if s then
  44. if under.name == "minecraft:cobblestone" then
  45. status = 1
  46. end
  47. if under.name == "minecraft:torch" then
  48. status = 4
  49. end
  50. if under.name == "minecraft:dirt" then
  51. turtle.back()
  52. turtle.turnLeft()
  53. end
  54. end --todo: check if on right y level, should be if s is false
  55.  
  56. if s2 then
  57. if front.name == "minecraft:chest" then
  58. turtle.turnLeft()
  59. turtle.turnLeft()
  60. status = 1
  61. end
  62. if front.name == "minecraft:log" then
  63. turtle.turnLeft()
  64. UpdateStatus()
  65. end
  66. if front.name == "minecraft:gravel" then
  67. turtle.turnLeft()
  68. turtle.turnLeft()
  69. end
  70. elseif status == 4 then
  71. turtle.forward()
  72. end
  73.  
  74. print("Updated Status: " .. lastStatus .. " to " .. status)
  75.  
  76. end
  77.  
  78. function CheckTree(side)
  79. if side == 1 then
  80. turtle.turnLeft()
  81. elseif side == 2 then
  82. turtle.turnRight()
  83. end
  84. local s, d = turtle.inspect()
  85. if s and d.name == "minecraft:log"
  86. return true
  87. else
  88. return false
  89. end
  90. end
  91.  
  92. function ChopTree(side)
  93. if CheckTree(side) then
  94. turtle.dig()
  95. for i = 1, 4 do
  96. turtle.dig()
  97. turtle.up()
  98. end
  99. for i = 1, 4 do
  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. MoveForward()
  147. ChopTree(1)
  148. ChopTree(2)
  149. end
  150.  
  151. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement