Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Podman 1.0
- -- by MCKerrnel
- --
- -- A ComputerCraft program to
- -- operate a farm in a 15dia
- -- pod/dome. Turtle will
- -- harvest and re-plant.
- -- Size of farm grid that turtle
- -- will traverse. Middle position
- -- is water.
- local width = 9
- local length = 9
- -- Fuel needed to start a cycle.
- local fuelCycle = 250
- -- Harvests and replants the crop.
- function harvestCrops(endCol)
- local colCount = 0
- while colCount < endCol do
- for rowCount = 1, length, 1 do
- turtle.select(1)
- -- Don't move forward if this is
- -- the first block in the row;
- -- we're already on it.
- if rowCount ~= 1 then
- turtle.forward()
- end
- -- Harvest the crop. If there
- -- is only one seed left in slot 1
- -- then do not plant it.
- turtle.digDown()
- if turtle.getItemCount(1) > 1 then
- turtle.placeDown()
- end
- end
- colCount = colCount + 1
- -- Rotate around to start
- -- the new row.
- endColTurn(colCount)
- turtle.forward()
- endColTurn(colCount)
- end
- end
- -- Determine which direction the
- -- turtle should turn, based on
- -- which row it just finished.
- function endColTurn(column)
- -- Turtle will snake, so odd
- -- numbered columns turn left,
- -- even turn right. Odd
- -- numbers will leave a
- -- remainder when divided by 2.
- local direction = column % 2
- if direction == 1 then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- -- Unloads the crops from the turtle
- -- into the chest for crops.
- function emptyHarvest()
- for slot = 2, 16, 1 do
- turtle.select(slot)
- turtle.drop()
- end
- end
- -- A quick function to convert a decimal
- -- value into an integer. Dunno why
- -- LUA has to be so difficult with this.
- -- Should be a built-in function!
- function toInt(decimalNum)
- local D2I = string.format("%i", decimalNum)
- return D2I
- end
- function refuel(fuelCycles)
- -- Refuel. We don't need a stupid
- -- amount of fuel, so cap it
- -- on refuel at 10k.
- local fuelMax = 10000
- if fuelCycles < 1 then
- -- Assume the turtle is facing
- -- forward and in-between the
- -- two chests. Left chest is
- -- to dump harvest into, right
- -- is for fuel.
- turtle.turnRight()
- turtle.select(2)
- -- Try to fill up, but if not enough to
- -- fill up, that's ok.
- while fuelCycles < 1 or turtle.getFuelLevel() < fuelMax do
- -- If there's nothing to grab, error out.
- if turtle.suck() == false then
- break
- end
- turtle.refuel()
- fuelCycles = turtle.getFuelLevel() / fuelCycle
- end
- -- If we still need fuel
- -- then alert console.
- if fuelCycles < 1 then
- print "NO FUEL: Reload the FUEL chest."
- end
- -- Restore original orientation.
- turtle.turnLeft()
- end
- return fuelCycles
- end
- -- Bring the turtle back at the end
- -- of the harvest cycle, dumping off
- -- the harvest and returning to
- -- between the chests. Assumption
- -- here is that the full 9x9 grid has
- -- been traveled. Function does not
- -- account for custom number of
- -- columns.
- function turtleReturn()
- for count = 1, 8, 1 do
- turtle.forward()
- end
- turtle.turnLeft()
- for count = 1, 5, 1 do
- turtle.forward()
- end
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- turtle.down()
- emptyHarvest()
- turtle.turnRight()
- end
- -- MAINLINE
- local fuelCycles = turtle.getFuelLevel() / fuelCycle
- print("Enough fuel to harvest ", toInt(fuelCycles), " cycles.")
- -- This is where it all happens.
- while true do
- -- We must have at least 1 seed in slot 1
- -- so that the slot never is empty, otherwise
- -- the turtle might try planting harvest items.
- -- If we do not have a seed, then abort.
- if turtle.getItemCount(1) == 0 then
- print("There is no target seed in slot 1.")
- print("Need at least ONE seed of the crop.")
- break
- end
- -- Fuel Up
- fuelCycles = turtle.getFuelLevel() / fuelCycle
- if fuelCycles < 1 then
- fuelCycles = refuel(fuelCycles)
- end
- -- If we have enough fuel, let's harvest!
- if fuelCycles >= 1 then
- turtle.up()
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.turnLeft()
- harvestCrops(width)
- -- Return to start
- turtleReturn()
- end
- -- To allow crops to grow to make
- -- harvesting worthwhile, we will
- -- wait 40 minutes. 60s * 40
- -- Can probably reduce this if
- -- using lilypad of fertility or
- -- something.
- sleep(2400)
- end
Advertisement
Add Comment
Please, Sign In to add comment