EphemeralKap

Untitled

Dec 4th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 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.  
  7. -- refuel the turtle with slot 1, coal
  8. function Refuel()
  9. turtle.select(1)
  10. turtle.refuel(3)
  11. end
  12.  
  13. --grabs fuel from coal chest
  14. function GrabFuel()
  15. turtle.turnLeft()
  16. turtle.select(1)
  17. turtle.suck()
  18. turtle.turnRight()
  19. end
  20.  
  21. -- move forward once and suck up items front, left and right
  22. function Forward()
  23. turtle.forward()
  24. turtle.suckDown()
  25. turtle.turnLeft()
  26. turtle.suck()
  27. turtle.turnRight()
  28. turtle.turnRight()
  29. turtle.suck()
  30. end
  31.  
  32. -- This function checks where the turtle is located on the rail, it's needed in case the program boots while the
  33. -- turtle is not at the start of the dropoff location
  34. function UpdateStatus()
  35. local s, under = turtle.inspectDown()
  36. local s2, front = turtle.inspect()
  37.  
  38.  
  39. lastStatus = status
  40. if s then
  41. if under.name == "minecraft:cobblestone" then
  42. status = 1
  43. end
  44. if under.name == "minecraft:torch" then
  45. status = 4
  46. end
  47. if under.name == "minecraft:dirt" then
  48. turtle.back()
  49. turtle.left()
  50. end
  51. end --todo: check if on right y level, should be if s is false
  52.  
  53. if s2 then
  54. if front.name == "minecraft:chest" then
  55. turtle.turnLeft()
  56. turtle.turnLeft()
  57. status = 1
  58. end
  59. if front.name == "minecraft:log" then
  60. turtle.turnLeft()
  61. UpdateStatus()
  62. end
  63. if front.name == "minecraft:gravel" then
  64. turtle.turnLeft()
  65. turtle.turnLeft()
  66. end
  67. elseif status == 4 then
  68. turtle.forward()
  69. end
  70.  
  71. print("Updated Status: " .. lastStatus .. " to " .. status)
  72.  
  73. end
  74.  
  75. -- main loop
  76. -- reset -> refuel -> pickup fuel -> chop -> deposit
  77. while true do
  78. if status == 0 or status == 4 then
  79. print("Updating status..")
  80. UpdateStatus()
  81. end
  82. if turtle.getItemCount(1) < 16 and status == 1 then
  83. print("Grabbing Fuel..")
  84. GrabFuel()
  85. end
  86. if turtle.getFuelLevel() < 5 then
  87. print("Refueling..")
  88. Refuel()
  89. end
  90. end
Advertisement
Add Comment
Please, Sign In to add comment