108 lines
2.2 KiB
Lua
108 lines
2.2 KiB
Lua
counter = 0
|
|
local function doCrop(parity)
|
|
if (counter % 5 == parity) then
|
|
turtle.placeDown()
|
|
end
|
|
counter = counter + 1
|
|
end
|
|
|
|
local function harvest()
|
|
local status, result = turtle.inspectDown()
|
|
if not status then
|
|
turtle.placeDown()
|
|
else
|
|
if result["name"] == "minecraft:potatoes" then
|
|
if result["state"]["age"] == 7 then
|
|
turtle.digDown()
|
|
turtle.placeDown()
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
local function doRefuel()
|
|
for i = 1,16 do
|
|
turtle.select(i)
|
|
if turtle.refuel(1) then
|
|
turtle.select(1)
|
|
return true
|
|
end
|
|
end
|
|
turtle.select(1)
|
|
return false
|
|
end
|
|
|
|
local function doAtChest()
|
|
-- remove items
|
|
print("Unloading Items...")
|
|
turtle.turnLeft()
|
|
for i = 2,16 do
|
|
turtle.select(i)
|
|
turtle.drop()
|
|
end
|
|
turtle.select(1)
|
|
turtle.turnRight()
|
|
turtle.turnRight()
|
|
-- refuel turtle
|
|
print("Refueling...")
|
|
while turtle.getFuelLevel() < 370 do
|
|
turtle.suckUp(1)
|
|
if (not doRefuel()) then
|
|
print("I am out of fuel. [r] to retry")
|
|
while true do
|
|
local event, key = os.pullEvent("key")
|
|
if key == keys.r then
|
|
break
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
local function whatDo()
|
|
harvest()
|
|
end
|
|
|
|
local function farm()
|
|
doAtChest()
|
|
whatDo() -- on start
|
|
print("Starting harvest...")
|
|
turtle.forward()
|
|
for i=1,9 do
|
|
for j=1,16 do
|
|
whatDo()
|
|
turtle.forward()
|
|
end
|
|
whatDo()
|
|
turtle.turnLeft()
|
|
turtle.back()
|
|
whatDo()
|
|
turtle.turnLeft()
|
|
for j=1,16 do
|
|
whatDo()
|
|
turtle.forward()
|
|
end
|
|
if i < 9 then
|
|
whatDo()
|
|
turtle.turnLeft()
|
|
turtle.forward()
|
|
whatDo()
|
|
turtle.turnLeft()
|
|
else
|
|
whatDo()
|
|
turtle.forward()
|
|
turtle.turnRight()
|
|
for j =1,17 do
|
|
whatDo()
|
|
turtle.forward()
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
while true do
|
|
farm()
|
|
print("Waiting 30 seconds...")
|
|
sleep(30)
|
|
end
|