Advertisement
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 PUMPKINS and MELONS 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 stem, don't break it.
- if string.match(blockDetected, "stem") then
- print("Don't break the stems!")
- else
- --If the detected block is a melon, break it.
- if string.match(blockDetected, "melon") then
- print("\nFound a Melon!")
- turtle.digDown()
- --If the detected block is a melon, break it.
- elseif string.match(blockDetected, "pumpkin") then
- print("\nFound a Pumpkin!")
- turtle.digDown()
- --If the detected block is neither a melon nor a pumpkin, leave it be.
- else
- print("\nFound", blockDetected, "I'll leave that.")
- end
- end
- else
- print("Nothing here!")
- 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.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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement