Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- 9 x 9 Farm Program for ComputerCraft Turtles.
- by GooGoo on Pastebin.
- Wade Catrett @ Youtube.
- ThaWade every where else.
- Caution: Be sure your wheat is fully grown before you start the program.
- It has no way to check if the wheat is fully grown or not.
- After the first harvest it waits 1 hour before harvesting again.
- Gives status updates of 30, 10, 5, and 1 minutes and final of 30 seconds.
- status updates = time until next harvest. Found at the very end of the code.
- Put a minium of 3 seeds in slot 1 and 2
- Put a minium of 2 coal in slot 16.
- Note: this is for a 9x9 farm
- D's are dirt/farmland.
- W is water.
- T = Turtle start position.
- C = Chest
- D D D D D D D D D
- D D D D D D D D D
- D D D D D D D D D
- D D D D D D D D D
- D D D D W D D D D
- D D D D D D D D D
- D D D D D D D D D
- D D D D D D D D D
- D D D D D D D D D
- C C
- ^
- Turtle goes on top of the left chest T C
- Right chest goes on the right side of the turtle. C <-GROWN_WHEAT->
- After you place him on the left most chest D D D D D D D D D
- ]]
- --HARVEST ROW START--
- local spot1 = turtle.getItemCount(1)
- local spot2 = turtle.getItemCount(2)
- function cropRow()
- turtle.select(1)
- turtle.forward()
- turtle.digDown()
- if spot1 > 1 then
- turtle.select(1)
- turtle.placeDown()
- elseif spot1 < 2 and spot2 > 1 then
- turtle.select(2)
- turtle.placeDown()
- elseif spot2 < 2 and spot1 > 1 then
- turtle.select(1)
- turtle.placeDown()
- else print("Not enough seeds to continue! Add atleast 3 seeds to slot 1 and 2.")
- end
- end
- --HARVEST ROW END--
- --TURN RIGHT START--
- function rightTurn()
- turtle.turnRight()
- turtle.select(2)
- turtle.forward()
- turtle.digDown()
- turtle.select(1)
- turtle.placeDown()
- turtle.turnRight()
- end
- --TURN RIGHT END--
- --TURN LEFT START--
- function leftTurn()
- turtle.turnLeft()
- turtle.select(2)
- turtle.forward()
- turtle.digDown()
- turtle.select(1)
- turtle.placeDown()
- turtle.turnLeft()
- end
- --TURN LEFT END--
- --RETURN HOME START--
- function returnHome()
- turtle.turnLeft()
- for i = 1, 8 do
- turtle.forward()
- end
- turtle.turnLeft()
- for i = 1, 9 do
- turtle.forward()
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- --RETURN HOME END--
- --REFUEL START--
- function refuel()
- turtle.select(16)
- print("Selecting slot 16 for fuel check.")
- sleep(3)
- if turtle.getFuelLevel() < 100 and turtle.refuel(0) == true then
- print("Fuel level is " ..turtle.getFuelLevel().. " Need atleast 100 for a full harvest.")
- sleep(3)
- print("Refueling")
- sleep(3)
- turtle.refuel(2)
- print("Refueled")
- end
- if turtle.getFuelLevel() < 100 and turtle.refuel(0) == false then
- print("Fuel level is " ..turtle.getFuelLevel().. " Need atleast 100 for a full run.")
- sleep(3)
- print("Please add fuel to slot 16.")
- sleep(2)
- print("Waiting 10 seconds for fuel.")
- sleep(10)
- turtle.refuel(2)
- end
- if turtle.getFuelLevel() < 100 and turtle.refuel(2) == false then
- print("TIMES UP! Come back when you have fuel! Exiting Program!")
- sleep(2)
- exit()
- else print("Fuel level is " ..turtle.getFuelLevel().. " Starting Work!")
- end
- end
- --REFUEL END--
- --COMPARE1&2 START--
- function compareOneToTwo()
- if turtle.select(1) == false then
- turtle.select(1)
- print("selecting slot 1")
- end
- if turtle.compareTo(2) == true then
- print("Items match!")
- elseif turtle.compareTo(2) == false then
- turtle.select(1)
- turtle.dropDown()
- print("Getting rid of mismatch items")
- else
- print("ERROR")
- end
- end
- --COMPARE1&2 END--
- local seeds1 = turtle.getItemCount(1)
- local seeds2 = turtle.getItemCount(2)
- local firstSlot,lastSlot = 3,15
- local firstSeed,lastSeed = 1,2
- local excess1, excess2 = 3,4
- --FILL SEEDS START--
- function grabSeeds()
- for i=firstSeed,lastSeed do
- if seeds1 < 64 then
- turtle.select(firstSeed)
- turtle.suck()
- print("Filling slot 1 with seeds!")
- elseif seeds2 < 64 then
- turtle.select(lastSeed)
- turtle.suck()
- print("Filling slot 2 with seeds!")
- else
- print("I have plenty of seeds!")
- end
- end
- end
- --FILL SEEDS END--
- --EMPTY INVENTORY START--
- function emptyInventory()
- for i=firstSlot,lastSlot do
- if turtle.select(i) and turtle.compareTo(lastSeed) == true then
- turtle.drop()
- print("Emptying inventory 'seeds'!")
- elseif turtle.select(i) and turtle.compareTo(2) == false then
- turtle.dropDown()
- print("Getting rid of everything but seeds!")
- end
- end
- end
- --EMPTY INVENTORY END--
- --EMPTY SEED OVERFLOW START--
- function emptyExcessSeeds()
- print("Getting rid of seed overflow!")
- for i = excess1,excess2 do
- if turtle.select(i) and turtle.compareTo(firstSeed,lastSeed) == true then
- turtle.drop()
- end
- end
- end
- --EMPTY SEED OVERFLOW END--
- --INVENTORY CLEANUP END--
- while true do
- refuel()
- print("Harvesting row 1.")
- for i = 1, 9 do
- cropRow()
- end
- for i = 1, 1 do
- rightTurn()
- end
- print("Harvesting row 2.")
- for i = 1, 8 do
- cropRow()
- end
- for i = 1, 1 do
- leftTurn()
- end
- print("Harvesting row 3.")
- for i = 1, 8 do
- cropRow()
- end
- for i = 1, 1 do
- rightTurn()
- end
- print("Harvesting row 4.")
- for i = 1, 8 do
- cropRow()
- end
- for i = 1, 1 do
- leftTurn()
- end
- print("Harvesting row 5.")
- for i = 1, 8 do
- cropRow()
- end
- for i = 1, 1 do
- rightTurn()
- end
- print("Harvesting row 6.")
- for i = 1, 8 do
- cropRow()
- end
- for i = 1, 1 do
- leftTurn()
- end
- print("Harvesting row 7.")
- for i = 1, 8 do
- cropRow()
- end
- for i = 1, 1 do
- rightTurn()
- end
- print("Harvesting row 8.")
- for i = 1, 8 do
- cropRow()
- end
- for i = 1, 1 do
- leftTurn()
- end
- print("Harvesting row 9.")
- for i = 1, 8 do
- cropRow()
- end
- print("Returning Home")
- for i = 1, 1 do
- returnHome()
- end
- turtle.turnRight()
- while compareOneToTwo() do
- end
- while emptyInventory() do
- return true
- end
- while grabSeeds() do
- return true
- end
- while emptyExcessSeeds() do
- return true
- end
- turtle.turnLeft()
- --status message Start
- print("Next harvest in 1 hour!")
- print("Resting!")
- os.sleep(1800)
- print("30 minutes remaining!")
- os.sleep(1200)
- print("10 minutes remaining!")
- os.sleep(300)
- print("5 minutes remaining!")
- os.sleep(240)
- print("1 minute remaining!")
- os.sleep(30)
- print("harvesting in 30 seconds.")
- sleep(30)
- --Status message End
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement