Cnibeck

Tree

Apr 9th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. -- Program to cut a 1x1 tree.
  2. -- ExCreationS V1
  3.  
  4. --[[place the turtle at the base of the tree.
  5.  
  6. Place a chest behind the turtle.
  7.  
  8. Bonemeal placed in slot 14,
  9. saplings placed in slot 15,
  10. fuel placed in slot 16.]]
  11.  
  12. -- Function for refueling
  13. function checkFuel()
  14. if turtle.getFuelLevel() <= 10 then
  15. if turtle.getItemCount(16) == 0 then
  16. print("Out of fuel.")
  17. exit()
  18. else
  19. turtle.select(16)
  20. turtle.refuel(1)
  21. turtle.select(1)
  22. end --if
  23. end --if
  24. end --checkFuel()
  25.  
  26. -- Create the function to turn around
  27. function turnAround()
  28. turtle.turnRight()
  29. turtle.turnRight()
  30. end --turnAround()
  31.  
  32. -- Function to deposit wood
  33. function dropOff()
  34. for slot = 1,13 do
  35. turtle.select(slot)
  36. turtle.drop()
  37. end --for
  38. end --dropOff()
  39.  
  40. -- Function to plant the sapling
  41. function plant()
  42. if turtle.getItemCount(15) >= 1 then
  43. turtle.select(15)
  44. turtle.place()
  45. turtle.select(1)
  46. else
  47. print("Not enough saplings.")
  48. exit()
  49. end --if
  50. end --plant()
  51.  
  52. -- Function to bonemeal new tree
  53. function bonemeal()
  54. if turtle.getItemCount(14) >= 1 then
  55. turtle.select(15)
  56. while turtle.compare() do
  57. turtle.select(14)
  58. turtle.place()
  59. turtle.select(15)
  60. end --while
  61. turtle.select(1)
  62. else
  63. print("Not enough bonemeal.")
  64. exit()
  65. end --if
  66. end --bonemeal()
  67.  
  68. -- Function to chop the tree
  69. function chopTree()
  70. turtle.dig()
  71. turtle.forward()
  72.  
  73. while turtle.detectUp() do
  74. checkFuel()
  75. turtle.digUp()
  76. turtle.up()
  77. end --while
  78.  
  79. while not turtle.detectDown() do
  80. turtle.down()
  81. end --while
  82. turtle.back()
  83. end --chopTree()
  84.  
  85. -- Main script
  86. print("")
  87. print(" [Tree Feller]")
  88. print(" Press enter to exit the program")
  89. print(" -----------------")
  90. print("")
  91. repeat
  92. print("How many trees should be felled:")
  93. local countTo = read()
  94. if tonumber(countTo) == nil or tonumber(countTo) == 0 then
  95. countTo = 0
  96. print(countTo, " tree(s) have been felled!")
  97. print("Goodbye...")
  98. sleep(2)
  99. break
  100. elseif tonumber(countTo) < 0 then
  101. print("That won't work..")
  102. else --if tonumber(countTo) > 0 then
  103. for index = 1, countTo do
  104. checkFuel()
  105. print("Chopping the tree...")
  106. chopTree()
  107. print("Depositing items...")
  108. turnAround()
  109. dropOff()
  110. turnAround()
  111. print("Planting new sapling...")
  112. plant()
  113. print("Using bonemeal...")
  114. bonemeal()
  115. end --for
  116. print(countTo, " tree(s) have been felled!")
  117. end --if
  118. until tonumber(countTo) > 0
Advertisement
Add Comment
Please, Sign In to add comment