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

Automatic Melon/Pumpkin Farm

Started by GalaxyMaster, 17 May 2013 - 11:07 AM
GalaxyMaster #1
Posted 17 May 2013 - 01:07 PM
Hi ComputerCrafters,

I just finished a fully automatic melon/pumpkin farm program. This is my second ComputerCraft program and I made it just a day after my first CC program: Automatic Tree Farm. I also made a fully automatic sugar cane farm program today. Link: Automatic Sugar Cane Farm. You need to give it fuel in the first slot. If it runs out of fuel, it will stop.

Note: This program currently only works with 2 lanes of melons/pumpkins. The length of the lanes doesn't matter though.

Note: You need to set up your farm like shown in this picture. The length of the lanes doesn't matter.
Spoiler
Please note that it is very important that the turtle starts in that position and that the 4 logs (can be any solid block) at the end of the lanes are there. The 4 logs (or any solid block) keep the melons/pumpkins from growing at those places. When that happens, the turtle won't mine them. Also, when it asks you for the length when you start it, it means the length of the dirt blocks holding the plants.


How to install:
SpoilerIf you have the http api installed:
Make a mining turtle and enter this:

pastebin get K7WrizsZ programname

You can replace programname with whatever you want the name of the program to be.

If you don't have the http api installed:
Make a mining turtle and make an empty program (name doesn't matter). Then go to your minecraft directory and then to saves, then your world, then computer and then the search the folders there for the program you just made. Open that file in notepad (or textedit for Mac users) and paste the code from here: http://pastebin.com/K7WrizsZ

Version history:
Spoiler1.1 - minor coding changes thanks to UNOBTANIUM and added a 1 minute wait after each lane switch.
1.0 - initial release

Screenshots:
Spoiler

Code:
Spoiler


write("Length: ")
length = read()
function moveForward(length)
  for i = 1, length do
    turtle.forward()
  end
end
function switchLanes()
  moveForward(2)
  turtle.turnLeft()
  moveForward(4)
  turtle.turnLeft()
  moveForward(1)
end
function roam()
  for i = 1, length do
    while turtle.getFuelLevel() <= 20 do
      turtle.select(1)
      turtle.refuel(1)
    end
    if turtle.detect() then
      turtle.dig()
    end
    moveForward(1)
  end
  switchLanes()
  sleep(60)
end

while true do
  roam()
end

Be sure to leave feedback and report any bugs you encounter. If you have questions feel free to ask them.
unobtanium #2
Posted 17 May 2013 - 02:13 PM
Here too:


if turtle.detect() then
  turtle.dig()
end
turtle.forward()

Much simpler! And you should really get into the for-loops and/or function stuff. They are really easy to copy-paste over and making programming a lot faster.
All these turtle.forward()s can be removed like this:

for i=1,3 do -- lets the turtle move 3 blocks forward
turtle.forward
end

And instead of making a for loop every time you can make a for loop into a function and just load up the function:


function moveForward(length)
for i=1,length do
  turtle.forward()
end
end

moveForward(3) --lets the turtle move 3 blocks forward
moveForward(100) -- lets the turtle move 100 blocks forward
GalaxyMaster #3
Posted 17 May 2013 - 03:57 PM
UPDATE: 1.1 - minor coding changes thanks to UNOBTANIUM and added a 1 minute wait after each lane switch.
unobtanium #4
Posted 17 May 2013 - 04:20 PM
Btw, you can name a function like you want to. moveForward was just an example. If you want to you can just name it f() and it would work as well ;D
GalaxyMaster #5
Posted 17 May 2013 - 04:31 PM
Btw, you can name a function like you want to. moveForward was just an example. If you want to you can just name it f() and it would work as well ;D
I know. I'm also very new to programming in general. So I won't really come up with complex stuff to solve problems.
mz2212 #6
Posted 09 August 2013 - 03:46 AM
One minor Improvement (for people that use no fuel mode)
Before:

    while turtle.getFuelLevel() <= 20 do
	  turtle.select(1)
	  turtle.refuel(1)
    end

After:

  if turtle.getFuelLevel() < 20 then
    turtle.select(1)
    turtle.refuel(1)
  else
    sleep(0.1)
  end

what it does is makes it so that if someone has the config set to unlimited fuel it wont throw an error
Phoenix #7
Posted 20 August 2013 - 03:43 AM
Oh lol, I have a farm program too, but yours looks pretty good.