DrFair

Force tree farm

Sep 10th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. height = 0
  2. treeNum = 1
  3.  
  4. function moveUp()
  5. if turtle.up() then
  6. height = height + 1
  7. end
  8. end
  9.  
  10. function moveDown()
  11. if turtle.down() then
  12. height = height - 1
  13. end
  14. end
  15.  
  16. function moveTo(h)
  17. while h < height do
  18. moveDown()
  19. end
  20. while h > height do
  21. moveUp()
  22. end
  23. end
  24.  
  25. function checkGrow()
  26. turtle.select(1)
  27. return not turtle.compare()
  28. end
  29.  
  30. function getSapling()
  31. print("Checking saplings.")
  32. if turtle.getItemCount(1) < 10 then
  33. print("Getting new saplings.")
  34. turtle.select(1)
  35. turtle.turnLeft()
  36. turtle.suck()
  37. turtle.turnRight()
  38. end
  39. end
  40.  
  41. function dropOff()
  42. print("Dropping off items.")
  43. turtle.turnRight()
  44. num = 2
  45. while turtle.getItemCount(num) > 0 do
  46. turtle.select(num)
  47. turtle.drop()
  48. num = num + 1
  49. end
  50. turtle.select(1)
  51. turtle.turnLeft()
  52. end
  53.  
  54. function checkFuel()
  55. print("Checking fuel ("..turtle.getFuelLevel()..").")
  56. while turtle.getFuelLevel() < 1000 do
  57. print("Refueling...")
  58. turtle.select(2)
  59. turtle.refuel(1)
  60. if turtle.getItemCount(2) == 0 then
  61. print("No wood to refuel with.")
  62. break
  63. end
  64. end
  65. if turtle.getFuelLevel() < 100 then
  66. print("Fuel at critical level, ended program.")
  67. return false
  68. end
  69. return true
  70. end
  71.  
  72. function chopTree()
  73. print("Chopping tree down.")
  74. while turtle.detect() do
  75. turtle.dig()
  76. turtle.digUp()
  77. moveUp()
  78. end
  79. print("Detected no more tree at height "..height..".")
  80. moveTo(0)
  81. turtle.select(1)
  82. print("Placing sapling.")
  83. while not turtle.place() do
  84. os.sleep(1)
  85. end
  86. if not checkFuel() then
  87. return false
  88. end
  89. getSapling()
  90. dropOff()
  91. return true
  92. end
  93.  
  94. while true do
  95. if checkGrow() then
  96. print("Detected tree number "..treeNum)
  97. if not chopTree() then
  98. break
  99. end
  100. treeNum = treeNum + 1
  101. else
  102. os.sleep(10)
  103. end
  104. end
Advertisement
Add Comment
Please, Sign In to add comment