Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Setup:
- --Place turtle with hoe on top of the
- --crop on the bottom left corner
- --of a rectangular field.
- --Place fuel in the last slot.
- --Config
- local farmWidth = 5
- local farmLength = 5
- -- Do not edit past this point
- -- unless you know what you are
- -- doing!
- local DIRECTIONS =
- {
- ["FORWARD"] = 1,
- ["BACKWARD"] = 2,
- ["LEFT"] = 3,
- ["RIGHT"] = 4
- }
- local posX = 1
- local posY = 1
- local direction = DIRECTIONS.FORWARD
- function refuel()
- local fuelNeeded = farmWidth * farmLength
- if fuelNeeded > turtle.getFuelLimit() then fuelneeded = turtle.getFuelLimit() end;
- while turtle.getFuelLevel() < fuelNeeded do
- turtle.select(16)
- local didRefuel = turtle.refuel()
- if not didRefuel then error("Need more fuel in the last slot!") end;
- end
- end
- function forward(int)
- for i=1,int do
- turtle.forward()
- end
- end
- function checkStatus()
- local wasSuccess, plantInfo = turtle.inspectDown()
- if type(plantInfo) == "string" then return false end;
- local plantName = plantInfo.name
- local plantAge = plantInfo.state.age
- if plantAge == 7 then return plantName end;
- return false
- end
- function scanInv(itemName)
- for i=1,15 do
- turtle.select(i)
- local item = turtle.getItemDetail()
- if item ~= nil and string.match(item.name, itemName) then
- return i
- end
- end
- return false
- end
- function harvest(plantName)
- local plantResource = string.match(plantName, ":(%S+)_")
- turtle.select(1)
- turtle.digDown()
- local slot = scanInv(":"..plantResource.."_seeds")
- if slot then
- turtle.placeDown()
- end
- end
- function reset()
- if direction == DIRECTIONS.FORWARD then turtle.turnLeft() end;
- if direction == DIRECTIONS.BACKWARD then turtle.turnRight() end;
- direction = DIRECTIONS.LEFT
- forward(farmWidth - 1)
- posY = 1
- if posX ~= 1 then
- turtle.turnLeft()
- forward(farmLength - 1)
- direction = DIRECTIONS.BACKWARD
- end
- if direction == DIRECTIONS.BACKWARD then
- turtle.turnLeft()
- turtle.turnLeft()
- elseif direction == DIRECTIONS.LEFT then
- turtle.turnRight()
- end
- posX = 1
- direction = DIRECTIONS.FORWARD
- end
- function main()
- for i=1, farmWidth do
- for j=1, farmLength do
- refuel()
- local isRipe = checkStatus()
- if isRipe then
- harvest(isRipe)
- end
- if posX < farmLength and direction == DIRECTIONS.FORWARD then
- turtle.forward()
- posX = posX + 1
- elseif posX > 1 and direction == DIRECTIONS.BACKWARD then
- turtle.forward()
- posX = posX - 1
- end
- end
- if posX == farmLength and posY ~= farmWidth then
- turtle.turnRight()
- turtle.forward()
- posY = posY + 1
- turtle.turnRight()
- direction = DIRECTIONS.BACKWARD
- elseif posX == 1 and posY ~= farmWidth then
- turtle.turnLeft()
- turtle.forward()
- posY = posY + 1
- turtle.turnLeft()
- direction = DIRECTIONS.FORWARD
- end
- end
- reset()
- end
- while true do
- main()
- os.sleep(60)
- end
Add Comment
Please, Sign In to add comment