local directions = {"north", "south", "east", "west"}
local curDir = 1
local function getDir()
local file = fs.open("curDir", "r")
if file then
local savedDir = file.readAll()
for k, dir in pairs(directions) do
if savedDir == dir then
curDir = k
end
end
end
end
local function turn(dir)
while directions[curDir] ~= dir do
if turtle.turnRight() then
curDir = curDir + 1
if curDir == 5 then
curDir = 1
end
local file = fs.open("curDir", "w")
file.write(directions[curDir])
file.flush()
file.close()
end
end
end
local function startup()
getDir()
end
local function clearInventory()
turn("east")
for i = 1, 16 do
local item = turtle.getItemDetail(i)
if item then
if item.name ~= "minecraft:bone_meal" then
turtle.select(i)
turtle.drop()
end
end
end
end
local function collectDrops()
repeat
until not turtle.suck()
end
local function growPlant()
turn("north")
repeat
until not turtle.suckUp()
for i = 1, 16 do
local item = turtle.getItemDetail(i)
if item then
if item.name == "minecraft:bone_meal" then
turtle.select(i)
repeat
if math.random(1,10) == 10 then
collectDrops()
end
until not turtle.place()
collectDrops()
end
end
end
end
local function feedChicken()
turn("south")
for i = 1, 16 do
local item = turtle.getItemDetail(i)
if item then
if item.name:match("chicken_food") then
turtle.select(i)
if not turtle.drop() then
break
end
end
end
end
end
local function produceBoneMeal()
turn("south")
local hasBones = false
for i = 1, 16 do
local item = turtle.getItemDetail(i)
if item then
if item.name == "minecraft:bone" then
hasBones = true
end
end
end
if not hasBones then
turtle.suck()
end
for i = 1, 16 do
local item = turtle.getItemDetail(i)
if item then
if item.name == "minecraft:bone" then
turtle.select(i)
if not turtle.dropUp() then
break
end
end
end
end
end
local function main()
while true do
clearInventory()
growPlant()
feedChicken()
produceBoneMeal()
end
end
startup()
main()