function plant()
-- move forward and plant the bone meal
for i=1,4 do
if turtle.detect() then
turtle.dig()
end
turtle.forward()
end
turtle.place()
turtle.turnRight()
turtle.turnRight()
-- move back to start position
for i=1,4 do
if turtle.detect() then
turtle.dig()
end
turtle.forward()
end
-- move 4 blocks to the left to start position of "farm"-mode
turtle.turnRight()
for i=1,4 do
if turtle.detect() then
turtle.dig()
end
turtle.forward()
end
turtle.turnRight()
-- reset turtle slot so flowers end up in the first 14 slots
turtle.select(1)
end
function farm()
local farmSize = 81
local direction = false
for x=1,farmSize do
if turtle.detect() then
turtle.dig()
end
turtle.forward()
-- everytime the turtle has moved 9 blocks it turns around, left or right depending on the direction variabel
if x % 9 == 0 then
if direction then
turtle.turnLeft()
if turtle.detect() then
turtle.dig()
end
turtle.forward()
turtle.turnLeft()
else
turtle.turnRight()
if turtle.detect() then
turtle.dig()
end
turtle.forward()
turtle.turnRight()
end
if direction then
direction = false
else
direction = true
end
end
end
-- back to start position
for i=1,9 do
if turtle.detect() then
turtle.dig()
end
turtle.forward()
end
turtle.turnRight()
for i=1,5 do
if turtle.detect() then
turtle.dig()
end
turtle.forward()
end
-- dump the content into the chest
turtle.turnLeft()
for i=1,13 do
turtle.select(i)
turtle.drop()
end
turtle.turnRight()
turtle.turnRight()
direction = false
end
function checkFuel()
-- checks if we still have fuel, if not turn it off
if turtle.getFuelLevel() < 81 then
error("insufficient fuel level")
end
end
local boneMeal = 14
function checkBoneMealSupply()
-- checks if we still have bone meal, if not turn it off
if turtle.getItemCount(boneMeal) == 0 then
boneMeal = boneMeal + 1
end
if boneMeal > 16 then
error("out of bone meal")
end
turtle.select(boneMeal)
end
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.")
print("Next, place a chest behind the turtle.")
print("Now place Bone Meal in the 14th, 15th and 16th slot of the turtle.")
print("Press Enter to start the program.")
while true do
local sEvent, param = os.pullEvent("key")
if sEvent == "key" then
if param == 28 then
print("Enter detected")
break
end
end
end
turtle.select(boneMeal)
while true do
checkFuel()
checkBoneMealSupply()
plant()
farm()
end