Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Configuration
- local FIELD_SIZE = 9
- local STORAGE_CONTROLLER = "storage" -- Adjust if necessary
- -- Wrap the storage controller
- local storage = peripheral.wrap(STORAGE_CONTROLLER)
- -- Function to check if a block is fully grown
- local function isMature()
- local success, block = turtle.inspectDown()
- if success and block.state and block.state.age == 7 then
- return true
- end
- return false
- end
- -- Function to find seeds in the turtle's inventory
- local function selectSeeds()
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item and (item.name:find("seeds") or item.name:find("sapling")) then
- turtle.select(slot)
- return true
- end
- end
- return false
- end
- -- Function to harvest and replant
- local function harvestAndReplant()
- if isMature() then
- turtle.digDown()
- if selectSeeds() then
- turtle.placeDown()
- end
- end
- end
- -- Function to move through the farm in a serpentine pattern
- local function navigateFarm()
- for row = 1, FIELD_SIZE do
- for col = 1, FIELD_SIZE - 1 do
- harvestAndReplant()
- turtle.forward()
- end
- harvestAndReplant()
- if row < FIELD_SIZE then
- if row % 2 == 1 then
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- end
- end
- end
- -- Return to starting position
- if FIELD_SIZE % 2 == 0 then
- turtle.turnRight()
- for i = 1, FIELD_SIZE - 1 do
- turtle.forward()
- end
- turtle.turnRight()
- else
- turtle.turnLeft()
- for i = 1, FIELD_SIZE - 1 do
- turtle.forward()
- end
- turtle.turnLeft()
- for i = 1, FIELD_SIZE - 1 do
- turtle.forward()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- end
- -- Function to deposit harvested crops into storage
- local function depositCrops()
- print("Depositing crops...")
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item and not (item.name:find("seeds") or item.name:find("sapling")) then
- turtle.select(slot)
- turtle.dropDown() -- Drop into the storage controller
- end
- end
- end
- -- Main loop
- while true do
- navigateFarm()
- depositCrops()
- print("Farm cycle complete. Sleeping for 5 minutes...")
- sleep(300) -- Wait 5 minutes before next harvest
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement