Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- This program will prompt the user for the length and width of the field to be harvested.
- It will then go through and dig up all GROWN WHEAT in that area, return home,
- drop off crops, refuel, and wait the specified time before running again.
- ]]
- --Sniff will inspect the block below the Turtle and break it only if it is a Melon or Pumpkin
- local function Sniff()
- --Detect the block. If it detects a block, it will decide what to do with it. Otherwise, it will see nothing there and continue on
- local success, data = turtle.inspectDown()
- if success then
- blockDetected = (data.name)
- --If the detected block is a Wheat, harvest it with right-click. Will not harvest non-fully grown wheat.
- if string.find(blockDetected, "wheat") then
- print("\nFound a crop! Leaving it if it isn't fully grown.")
- --Harvest the crop
- turtle.select(16)
- turtle.placeDown()
- --Pickup item 1
- turtle.select(1)
- turtle.suckDown()
- --Pickup item 2
- turtle.select(2)
- turtle.suckDown()
- else
- print("\nFound", blockDetected, "I'll leave that.")
- end
- else
- print("Nothing here!")
- --Pickup item 1 (in case an item popped too far)
- turtle.select(1)
- turtle.suckDown()
- --Pickup item 2
- turtle.select(2)
- turtle.suckDown()
- end
- end
- --This function moves the Turtle forward "width", sniffing at every block.
- local function Patrol()
- i = 0
- repeat
- turtle.forward()
- Sniff()
- i = i + 1
- until(i>=width)
- end
- --This function turns the Turtle RIGHT in preparation for the next Patrol function and sniffs the first block.
- local function turnRight()
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- Sniff()
- end
- --This function turns the Turtle LEFT in preparation for the next Patrol function and sniffs the first block.
- local function turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- Sniff()
- end
- --This function refuels the Turtle and prints out fuel level.
- local function Refuel()
- turtle.select(1)
- print("Refueling!")
- turtle.refuel()
- fuel = turtle.getFuelLevel()
- print("I can move", fuel, "more blocks!")
- end
- --The main function. Runs Patrol and the Turn functions until the inputted length is met
- local function Harvest()
- laps = 1
- Refuel()
- repeat
- print("Starting Lap #", laps)
- Patrol()
- turnRight()
- laps = laps + 1
- print("Starting Lap #", laps)
- Patrol()
- turnLeft()
- laps = laps + 1
- until (laps>=length)
- end
- --This function returns the Turtle to the home position one the Harvest function ends. On the way, it drops off items and picks up fuel.
- local function Home()
- print("Area completed! Returning home.")
- turtle.turnLeft()
- j = 1
- repeat
- turtle.forward()
- j = j + 1
- until(j==length)
- print("Dropping off items!")
- turtle.select(1)
- turtle.dropDown()
- turtle.select(2)
- turtle.dropDown()
- turtle.select(3)
- turtle.dropDown()
- turtle.select(4)
- turtle.dropDown()
- turtle.select(5)
- turtle.dropDown()
- turtle.select(6)
- turtle.dropDown()
- turtle.select(7)
- turtle.dropDown()
- turtle.select(8)
- turtle.dropDown()
- turtle.select(9)
- turtle.dropDown()
- turtle.select(10)
- turtle.dropDown()
- turtle.select(11)
- turtle.dropDown()
- turtle.select(12)
- turtle.dropDown()
- turtle.select(13)
- turtle.dropDown()
- turtle.select(14)
- turtle.dropDown()
- turtle.select(15)
- turtle.dropDown()
- turtle.forward()
- print("Picking up some fuel!")
- turtle.select(1)
- turtle.suckDown(10)
- turtle.turnRight()
- end
- --START OF PROGRAM
- io.write("\nHi there! \nI should begin placed above a chest full of fuel. That is my home position. \nDirectly to the right of the fuel chest, place a seperate (NOT CONNECTED!) chest for me to dump your delicious crops into!\nI'll go through and harvest everything in the defined area, drop if off, refuel, and patiently wait at the home position to start again after the defined sleep time.")
- io.write("\nWhat is the width of the field?")
- width = tonumber(io.read())
- print("\nOkay!", width, "Wide!")
- io.write("\nWhat is the length of the field?")
- length = tonumber(io.read())
- print("\nOkay!", length, "Long!")
- io.write("\nHow many minutes should I sleep between each Harvest?")
- sleep = tonumber(io.read()) * 60
- print("Got it. I'll chill out for", sleep, "seconds between Harvests!")
- print("Starting the Harvest!")
- loop = 1
- repeat
- Harvest()
- Home()
- print("Sleeping for", sleep/60, "minutes. Zzz...")
- os.sleep(sleep)
- until(loop~=1)
Add Comment
Please, Sign In to add comment