Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Constants
- requiredWheat = 48
- requiredFuel = 500
- waitTime = 6*60 -- Seconds between breed cycles
- fuelDirection = "right"
- wheatDirection = "up"
- -- Breeds the cows with Wheat
- function breed()
- -- Power the water in the farm
- redstonePulse()
- -- Wait for cows
- os.sleep(1)
- -- Place wheat
- for i=1,200,1 do
- turtle.place()
- end
- -- Turn off water
- redstonePulse()
- end
- -- Fires a 2 tick pulse of redstone on the left and right of the turtle
- function redstonePulse()
- redstone.setOutput("left", true)
- redstone.setOutput("right", true)
- os.sleep(0.2)
- redstone.setOutput("left", false)
- redstone.setOutput("right", false)
- end
- -- Select the next slot
- function selectNext()
- if turtle.getSelectedSlot() == 16 then
- turtle.select(1)
- else
- turtle.select(turtle.getSelectedSlot()+1)
- end
- end
- -- Go through all the stations and perform a breed cycle
- function breedCycle()
- turtle.select(1)
- print("Starting breed cycle")
- -- Check fuel
- if turtle.getFuelLevel() < requiredFuel then
- getFuel(fuelDirection)
- end
- if turtle.getItemCount() < requiredWheat then
- getWheat(wheatDirection)
- end
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- breed()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.forward()
- breed()
- turtle.back()
- turtle.turnRight()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- breed()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.forward()
- breed()
- turtle.back()
- turtle.turnRight()
- for i=1,7,1 do
- turtle.back()
- end
- end
- function getFuel(direction)
- print("Refueling")
- turtle.select(16)
- local success = false
- local alreadyComplained = false;
- -- Face chest
- if direction=="left" then
- turtle.turnLeft()
- end
- if direction=="right" then
- turtle.turnRight()
- end
- while not success do
- os.queueEvent("randomEvent")
- os.pullEvent()
- -- Get the fuel
- if direction=="down" then
- turtle.suckDown()
- end
- if direction=="up" then
- turtle.suckUp()
- end
- if direction=="left" then
- turtle.suck()
- end
- if direction=="right" then
- turtle.suck()
- end
- -- Attempt refuel
- turtle.refuel()
- success = turtle.getFuelLevel() >= requiredFuel
- -- Place item back in chest if bucket
- if direction=="down" then
- turtle.dropDown()
- end
- if direction=="up" then
- turtle.dropUp()
- end
- if direction=="left" or direction=="right" then
- turtle.drop()
- end
- -- Complain if unsuccessfull
- if not success and not alreadyComplained then
- print("Not enough fuel. Please place fuel in chest.")
- alreadyComplained = true
- end
- end
- turtle.select(1)
- print("Fuel at "..string.format(turtle.getFuelLevel()).."/"..string.format(requiredFuel))
- -- Face forward
- if direction=="left" then
- turtle.turnRight()
- end
- if direction=="right" then
- turtle.turnLeft()
- end
- end
- function getWheat(direction)
- print("Obtaining wheat")
- local success = false
- local alreadyComplained = false
- turtle.select(1)
- local numWheat = turtle.getItemSpace()
- -- Face chest
- if direction=="left" then
- turtle.turnLeft()
- end
- if direction=="right" then
- turtle.turnRight()
- end
- while not success do
- os.queueEvent("randomEvent")
- os.pullEvent()
- -- Get the wheat
- if direction=="down" then
- turtle.suckDown(numWheat)
- end
- if direction=="up" then
- turtle.suckUp(numWheat)
- end
- if direction=="left" then
- turtle.suck(numWheat)
- end
- if direction=="right" then
- turtle.suck(numWheat)
- end
- -- See if I have enough
- success = turtle.getItemCount() >= requiredWheat
- -- Complain if unsuccessfull
- if not success and not alreadyComplained then
- print("Not enough wheat. Please place "..requiredWheat-turtle.getItemCount().." wheat in the chest.")
- alreadyComplained = true
- end
- end
- -- Face forward
- if direction=="left" then
- turtle.turnRight()
- end
- if direction=="right" then
- turtle.turnLeft()
- end
- print("Wheat obtained")
- end
- -- Main loop
- function main()
- while true do
- breedCycle()
- os.sleep(waitTime)
- end
- end
- main()
Add Comment
Please, Sign In to add comment