Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Place a turtle on top of a chest with a redstone input comming from the side.
- -- On a straight line from that path, place redstone signals that can catch the turtle from below.
- -- When the turtle finds a redstone signal, it will turn right and do the following:
- -- > Go forward once, and read a single number in the disk file called "cropstage.txt", to know at which metadata to harvest the crop
- -- > Go forward and farm until it hits a wall, setting the depth of the farm. Turn right and come back one tile over.
- -- > Go back and forth, each time going one more tile to the right, until it hits another wall.
- -- > Go back to the point of origin, pointing the oposite way as from the start
- -- If nothing was harvested, the turtle will continue forward until it hits another torch.
- -- If something was harvested, the turtle will go back home and drop its cargo in the chest.
- local maxFarmSize = 20
- local startInputSide = "left"
- local neededFarmInputSide = "bottom"
- local forward = 0
- local returning = false
- local function farmTile(cropStage)
- local success, detail = turtle.inspectDown()
- if (success) then
- if (detail.metadata == cropStage) then
- turtle.digDown()
- turtle.suckDown()
- if (turtle.getItemCount() > 1) then
- turtle.placeDown()
- end
- return true
- else
- turtle.suckDown()
- end
- else
- if (turtle.getItemCount() > 1) then
- turtle.placeDown()
- end
- turtle.suckDown()
- end
- return false
- end
- local function dropCargo()
- for i=1, 16 do
- turtle.select(i)
- turtle.dropDown()
- end
- turtle.select(1)
- end
- local function farmPass(cropStage)
- local depth = 0
- local width = 1
- local farmedSomething = false
- turtle.select(1)
- while true do
- if (depth == 0) then
- while turtle.forward() do
- depth = depth+1
- farmTile(cropStage)
- end
- depth = depth-1
- else
- for i=1, depth do
- turtle.forward()
- if (farmTile(cropStage)) then
- farmedSomething = true
- end
- end
- end
- turtle.turnRight()
- turtle.forward()
- if (farmTile(cropStage)) then
- farmedSomething = true
- end
- turtle.turnRight()
- for i=1, depth do
- turtle.forward()
- if (farmTile(cropStage)) then
- farmedSomething = true
- end
- end
- turtle.turnLeft()
- if (turtle.forward()) then
- if (farmTile(cropStage)) then
- farmedSomething = true
- end
- width = width+2
- turtle.turnLeft()
- else
- turtle.turnRight()
- turtle.turnRight()
- for i=1, width do
- turtle.forward()
- end
- turtle.turnLeft()
- turtle.forward()
- return farmedSomething
- end
- end
- end
- while true do
- forward = 0
- returning = false
- -- Wait for redstone signal to start
- while not rs.getInput(startInputSide) do
- os.pullEvent("redstone")
- print("Redstone update")
- end
- -- Go forward until...
- repeat
- turtle.forward()
- forward = forward+1
- -- ...it gets a redstone signal
- if (rs.getInput(neededFarmInputSide)) then
- turtle.turnRight()
- turtle.forward()
- local file = fs.open("disk/cropstage.txt", "r")
- local cropStage = file.readLine()
- file.close()
- returning = farmPass(tonumber(cropStage))
- turtle.forward()
- turtle.turnRight()
- if (returning) then
- break
- end
- end
- until turtle.detect() -- ...or you hit a wall
- turtle.up()
- for i=1, forward do
- turtle.back()
- end
- turtle.down()
- dropCargo()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement