1. function plant()
  2. -- move forward and plant the bone meal
  3. for i=1,4 do
  4. if turtle.detect() then
  5. turtle.dig()
  6. end
  7. turtle.forward()
  8. end
  9.  
  10. turtle.place()
  11. turtle.turnRight()
  12. turtle.turnRight()
  13.  
  14. -- move back to start position
  15. for i=1,4 do
  16. if turtle.detect() then
  17. turtle.dig()
  18. end
  19. turtle.forward()
  20. end
  21.  
  22. -- move 4 blocks to the left to start position of "farm"-mode
  23. turtle.turnRight()
  24. for i=1,4 do
  25. if turtle.detect() then
  26. turtle.dig()
  27. end
  28. turtle.forward()
  29. end
  30. turtle.turnRight()
  31.  
  32. -- reset turtle slot so flowers end up in the first 14 slots
  33. turtle.select(1)
  34. end
  35.  
  36. function farm()
  37. local farmSize = 81
  38. local direction = false
  39. for x=1,farmSize do
  40. if turtle.detect() then
  41. turtle.dig()
  42. end
  43. turtle.forward()
  44.  
  45. -- everytime the turtle has moved 9 blocks it turns around, left or right depending on the direction variabel
  46. if x % 9 == 0 then
  47. if direction then
  48. turtle.turnLeft()
  49. if turtle.detect() then
  50. turtle.dig()
  51. end
  52. turtle.forward()
  53. turtle.turnLeft()
  54. else
  55. turtle.turnRight()
  56. if turtle.detect() then
  57. turtle.dig()
  58. end
  59. turtle.forward()
  60. turtle.turnRight()
  61. end
  62.  
  63. if direction then
  64. direction = false
  65. else
  66. direction = true
  67. end
  68. end
  69. end
  70.  
  71. -- back to start position
  72. for i=1,9 do
  73. if turtle.detect() then
  74. turtle.dig()
  75. end
  76. turtle.forward()
  77. end
  78. turtle.turnRight()
  79. for i=1,5 do
  80. if turtle.detect() then
  81. turtle.dig()
  82. end
  83. turtle.forward()
  84. end
  85.  
  86. -- dump the content into the chest
  87. turtle.turnLeft()
  88. for i=1,13 do
  89. turtle.select(i)
  90. turtle.drop()
  91. end
  92.  
  93. turtle.turnRight()
  94. turtle.turnRight()
  95.  
  96. direction = false
  97. end
  98.  
  99. function checkFuel()
  100. -- checks if we still have fuel, if not turn it off
  101. if turtle.getFuelLevel() < 81 then
  102. error("insufficient fuel level")
  103. end
  104. end
  105.  
  106. local boneMeal = 14
  107. function checkBoneMealSupply()
  108. -- checks if we still have bone meal, if not turn it off
  109. if turtle.getItemCount(boneMeal) == 0 then
  110. boneMeal = boneMeal + 1
  111. end
  112. if boneMeal > 16 then
  113. error("out of bone meal")
  114. end
  115. turtle.select(boneMeal)
  116. end
  117.  
  118. print("First, place the turtle and make a 9x9 square area infront of the turtle, with five blocks on the right side of it, and four on the left.")
  119. print("Next, place a chest behind the turtle.")
  120. print("Now place Bone Meal in the 14th, 15th and 16th slot of the turtle.")
  121. print("Press Enter to start the program.")
  122.  
  123. while true do
  124. local sEvent, param = os.pullEvent("key")
  125. if sEvent == "key" then
  126. if param == 28 then
  127. print("Enter detected")
  128. break
  129. end
  130. end
  131. end
  132.  
  133. turtle.select(boneMeal)
  134. while true do
  135. checkFuel()
  136. checkBoneMealSupply()
  137. plant()
  138. farm()
  139. end