That part works perfectly. However, near the end, I wanted to automatically craft bread and throw it in the chest before it, but it's not really working out very nicely.
Here's the part of the script that controls bread crafting:
local total = 0
for i=1, 16 do
total = total + turtle.getItemCount(i)
end
for i=1, 16 do
if turtle.getItemCount(i) > 0 then
turtle.select(i)
repeat until not turtle.dropDown(1)
end
end
for slot=1, 3 do
turtle.select(slot)
for w=1, math.ceil(total/3) do
if not turtle.suckDown() then
break
end
end
end
turtle.craft(turtle.getItemCount(1))
My logic with this was to throw out anything that isn't wheat (in slot 1) in the chest in front, then count all of the remaining items, which all should be wheat. Then it drops all of the items down, 1 by 1. After that, it sucks up a third of the dropped items into slots 1, 2, and 3, then crafts it at the end.
The full code:
Spoiler
local function wheat()
turtle.select(1)
turtle.digDown()
turtle.select(2)
turtle.placeDown()
turtle.forward()
end
for x=1, 9 do
for y=1, 6 do
wheat()
end
if x ~= 9 then
if x%2 == 1 then
turtle.turnRight()
wheat()
turtle.turnRight()
else
turtle.turnLeft()
wheat()
turtle.turnLeft()
end
end
end
local function melon()
turtle.select(5)
turtle.digDown()
turtle.forward()
end
turtle.forward()
turtle.turnLeft()
for i=1, 8 do
melon()
end
turtle.turnLeft()
melon()
for i=1, 6 do
turtle.forward()
end
turtle.select(1)
for i=2, 16 do
if not turtle.compareTo(i) then
turtle.select(i)
turtle.drop()
turtle.select(1)
end
end
local total = 0
for i=1, 16 do
total = total + turtle.getItemCount(i)
end
for i=1, 16 do
if turtle.getItemCount(i) > 0 then
turtle.select(i)
turtle.dropDown(1)
end
end
for slot=1, 3 do
turtle.select(slot)
for w=1, math.ceil(total/3) do
if not turtle.suckDown() then
break
end
end
end
turtle.craft(turtle.getItemCount(1))
for i=1, 16 do
turtle.select(i)
turtle.drop()
end
turtle.turnLeft()
turtle.turnLeft()
At the end, it only drops everything on the ground. That or just throws all the wheat in the chest, uncrafted. What am I doing wrong here?