This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Pho3niX90's profile picture

[1.5.1] Auto Farming Bot

Started by Pho3niX90, 23 September 2012 - 10:22 PM
Pho3niX90 #1
Posted 24 September 2012 - 12:22 AM
So tried ComputerCraft for the first time today. And decided to create a Auto Farming BOT, that plows a field, plants a wheat, and then uses bonemeal to instant grow the crop, then takes the wheat..

When the Seeds or bonemeal reaches 1, it will turn to the chests, replenish items, and store wheat.

PLEASE NOTE:
  • The turtle must have a pickaxe, not a hoe.
  • There musn't be a field/crop in-front of the turtle like in the pic, otherwise the turtle will spin in circles looking for a place to plant
Here's the code.

Sourceforge Link: https://sourceforge.net/projects/ccawf/?source=navbar

1.4

term.clear()
term.setCursorPos(1,1)
print("X90 Farming Robot")

while turtle.detect() do
turtle.turnRight()
end

function getSeeds()
turtle.turnLeft()
turtle.select(1)
turtle.drop()
while turtle.getItemCount(1) < 10 do
turtle.suck()
end
turtle.turnRight()
end
function getBone()
turtle.turnRight()
turtle.select(2)
turtle.drop()
while turtle.getItemCount(2) < 10 do
turtle.suck()
end
turtle.turnLeft()
end

function StoreItems()
turtle.turnLeft()
for i=3,16 do
turtle.select(i)
if turtle.compareTo(1) then
turtle.drop()
end
end
turtle.turnRight()
turtle.turnRight()
for i=3,16 do
turtle.select(i)
if turtle.compareTo(2) then
turtle.drop()
end
end
turtle.turnLeft()
turtle.turnRight()
turtle.turnRight()
for i=3,16 do
turtle.select(i)
turtle.drop()
end
turtle.turnLeft()
turtle.turnLeft()
end


Farm = turtle.getItemCount(1)
Bone = turtle.getItemCount(2)
if Farm > Bone then
doTill = Bone
else
doTill = Farm
end
if Farm <= 1 or Bone <= 1 then

StoreItems()
getSeeds()
getBone()

end

i = 1

while i < doTill do
turtle.dig()
turtle.select(1)
turtle.place()
turtle.select(2)
turtle.place()
turtle.dig()
i = i+1
end
os.reboot()

1.5.1

term.clear()
term.setCursorPos(1,1)
print("X90 Farming Robot")
while turtle.detect() do
turtle.turnRight()
end
function getSeeds()
turtle.turnLeft()
turtle.select(1)
if turtle.getItemCount(1) > 0 then
turtle.drop()
end
while turtle.getItemCount(1) < 10 do
turtle.suck()
end
turtle.turnRight()
end
function getBone()
turtle.turnRight()
turtle.select(2)
if turtle.getItemCount(2) > 0 then
turtle.drop()
end
while turtle.getItemCount(2) < 10 do
turtle.suck()
end
turtle.turnLeft()
end
function StoreItems()
turtle.turnLeft()
for i=3,16 do
turtle.select(i)
if turtle.compareTo(1) then
if turtle.getItemCount(i) > 0 then
turtle.drop()
end
end
end
turtle.turnRight()
turtle.turnRight()
for i=3,16 do
turtle.select(i)
if turtle.compareTo(2) then
if turtle.getItemCount(i) > 0 then
turtle.drop()
end
end
end
turtle.turnRight()
for i=3,16 do
turtle.select(i)
if turtle.getItemCount(i) > 0 then
turtle.drop()
end
end
turtle.turnLeft()
turtle.turnLeft()
end

Farm = turtle.getItemCount(1)
Bone = turtle.getItemCount(2)
if Farm > Bone/3 then
doTill = Bone/3
else
doTill = Farm
end
if Farm <= 1 or Bone <= 3 then
StoreItems()
getSeeds()
getBone()
end
i = 1
while i < doTill do
turtle.dig()
turtle.select(1)
turtle.place()
turtle.select(2)
turtle.place()
turtle.place()
turtle.place()
turtle.dig()
i = i+1
end
os.reboot()

Please view attached image to see the setup you must follow to accomplish this.
[attachment=479:auto farm bot.png]
Bushido #2
Posted 04 October 2012 - 08:20 PM
I have it set up right but it turns to the seed chest and gives the error farm:32: attempt to call nil

If i have the wheat allrdy down it just spins in a circle
Pho3niX90 #3
Posted 15 October 2012 - 07:45 PM
I have it set up right but it turns to the seed chest and gives the error farm:32: attempt to call nil

If i have the wheat allrdy down it just spins in a circle

Sorry for only responding now, what turtle are you using? And what version of minecraft and computercraft are you using? Please put a seed in the first slot and let me know what happens.
Pho3niX90 #4
Posted 08 April 2013 - 09:33 AM
Here is updated code for the new version, this fixes the issue where it drops everything and never farms.

a note to everyone, when first creating your farm, make sure that the pathc where the wheat is in the picture doesn't actually contain a crop, otherwise your turtle will spin in circles looking for a place to start it's own farm.

Also, the code below should be name "startup" program, nothing else.



term.clear()
term.setCursorPos(1,1)
print("X90 Farming Robot")
while turtle.detect() do
turtle.turnRight()
end
function getSeeds()
turtle.turnLeft()
turtle.select(1)
if turtle.getItemCount(1) > 0 then
turtle.drop()
end
while turtle.getItemCount(1) < 10 do
turtle.suck()
end
turtle.turnRight()
end
function getBone()
turtle.turnRight()
turtle.select(2)
if turtle.getItemCount(2) > 0 then
turtle.drop()
end
while turtle.getItemCount(2) < 10 do
turtle.suck()
end
turtle.turnLeft()
end
function StoreItems()
turtle.turnLeft()
for i=3,16 do
turtle.select(i)
if turtle.compareTo(1) then
if turtle.getItemCount(i) > 0 then
turtle.drop()
end
end
end
turtle.turnRight()
turtle.turnRight()
for i=3,16 do
turtle.select(i)
if turtle.compareTo(2) then
if turtle.getItemCount(i) > 0 then
turtle.drop()
end
end
end
turtle.turnRight()
for i=3,16 do
turtle.select(i)
if turtle.getItemCount(i) > 0 then
turtle.drop()
end
end
turtle.turnLeft()
turtle.turnLeft()
end

Farm = turtle.getItemCount(1)
Bone = turtle.getItemCount(2)
if Farm > Bone/3 then
doTill = Bone/3
else
doTill = Farm
end
if Farm <= 1 or Bone <= 3 then
StoreItems()
getSeeds()
getBone()
end
i = 1
while i < doTill do
turtle.dig()
turtle.select(1)
turtle.place()
turtle.select(2)
turtle.place()
turtle.place()
turtle.place()
turtle.dig()
i = i+1
end
os.reboot()