Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. if not turtle then
  2. print("This program will only run on a turtle.")
  3. return
  4. end
  5.  
  6. if turtle.getFuelLevel() == 0 then
  7. print("Please refuel the turtle before running this program.")
  8. end
  9.  
  10. if turtle.getItemCount(1) == 0 then
  11. print("You must put the type of sapling you wish to farm in the first slot before running this program.")
  12. return
  13. end
  14.  
  15. if turtle.getItemCount(2) == 0 then
  16. print("You must put the type of log you wish to farm in the second slot before running this program.")
  17. return
  18. end
  19.  
  20. -- Attempt to refuel if under a given fuel level
  21. function refuelAt(fuelLevel)
  22. local fuelRemaining = turtle.getFuelLevel()
  23.  
  24. if fuelRemaining == "unlimited" then
  25. return true
  26. end
  27.  
  28. if turtle.getFuelLevel() > fuelLevel then
  29. return true
  30. end
  31.  
  32. -- Never refuel using the slots 1 and 2, which contain
  33. -- the type of log we're harvesting as well as the sapling
  34. -- we'll be replanting
  35. for i = 3, 16 do
  36. local itemsLeft = turtle.getItemSpace(i)
  37.  
  38. turtle.select(i)
  39. if turtle.refuel(itemsLeft) then
  40. return true
  41. end
  42. end
  43. end
  44.  
  45. function chopTree()
  46. local height = 1
  47.  
  48. turtle.dig()
  49. turtle.forward()
  50.  
  51. -- Dig up the trunk of the tree
  52. turtle.select(2)
  53. while turtle.compareUp() do
  54. turtle.digUp()
  55. turtle.up()
  56. height = height + 1
  57. end
  58.  
  59. -- Return to where we started
  60. for i = 1, height do
  61. turtle.down()
  62. end
  63.  
  64. turtle.back()
  65. end
  66.  
  67. while true do
  68. print("Tree farm initiated!")
  69. print("This turtle will now wait for a sapling in front of it to grow!")
  70. print("Plant a sapling in front of the turtle and come back later to collect any wood your turtle has harvested.")
  71. print()
  72. print("To exit, press and hold CTRL+T")
  73.  
  74. -- Wait for a sapling to grow
  75. turtle.select(2)
  76. while not turtle.compare()
  77. do
  78. turtle.turnLeft()
  79. turtle.turnLeft()
  80. turtle.select(1)
  81. turtle.suck()
  82. turtle.turnLeft()
  83. turtle.turnLeft()
  84. for i = 3, 16
  85. do
  86. turtle.select(i)
  87. turtle.dropDown()
  88. end
  89. turtle.select(2)
  90. end
  91.  
  92. chopTree()
  93. refuelAt(500)
  94.  
  95. -- Plant the next sapling to harvest
  96. turtle.select(1)
  97. turtle.place()
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement