Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- robot.api = require("robot")
- component.api = require("component")
- print("Robot crop farm! (Before starting, ensure you have seeds in the first slot [it'll tell you where else you need to put them for first time autoplanting] and fuel in the last 2 slots before continuing with this program)")
- print("Length? (the way the robot is facing.)")
- Length = tonumber(read())
- if Length == 0 then
- print("Invalid")
- else do
- print("Width?")
- Width = tonumber(read())
- SeedSlotAmount = Length*Width/64
- SeedSlotAmount = math.ceil(SeedSlotAmount)
- if SeedSlotAmount>14 then
- SeedSlotAmount = 14
- end
- print("Delay between farming sessions?")
- Delay = tonumber(read())
- print("Do you want to have the robot plant them for the first run as a first time?")
- FirstRun = read()
- if FirstRun == "yes" then
- FirstRun = true
- print("Okay farming time make sure you have seeds in slots 1- "..SeedSlotAmount.." and fuel in the last 2 slots.")
- elseif FirstRun == "no" then
- FirstRun = false
- print("Okay farming time just have fuel in the last 2 slots.")
- else
- print("Invalid.")
- end
- end
- end
- TurtleXPos = 1
- TurtleYPos = 1
- turnLeft = false
- changeXPos = false
- function changeReverseXPos()
- if changeXPos == false then
- changeXPos = true
- else
- changeXPos = false
- print(changeXPos)
- end
- end
- SeedCount = Length*Width
- function checkFirst()
- local x
- if robot.count([slot: 1])==0 then
- print("No seeds in first slot!")
- repeat
- sleep(1)
- until robot.count([slot: 1])>=1
- end
- end
- function checkSeedCount()
- local SlotNum = 5
- local x
- local y = false
- SeedAmount = 0
- for x=1,SeedSlotAmount do
- if robot.count([slot: SlotNum])>0 then
- SeedAmount = robot.count([slot: SlotNum])
- elseif robot.count([slot: SlotNum])==0 then
- if robot.select([slot: SlotNum])<19 then
- repeat
- SlotNum=SlotNum+1
- robot.select([slot: SlotNum])
- sleep(0.5)
- until robot.select([slot: SlotNum])==19
- end
- if robot.select([slot: SlotNum])==19 then
- robot.select([slot: 19])
- end
- end
- if robot.count([slot: SlotNum])==0 and robot.select([slot: SlotNum])==19 then
- SlotNum = 1
- print("Out of seeds")
- repeat
- sleep(1)
- until robot.count([slot: SlotNum])>0
- robot.select([slot: 1])
- end
- end
- return SeedAmount
- end
- function doRefuel()
- local slotNum = 15
- local TurtleXPoss = TurtleXPos
- local TurtleYPoss = TurtleYPos
- local TurtleXPosss = TurtleXPos
- local TurtleYPosss = TurtleYPos
- local g
- local j
- local l
- local h
- local k
- local v
- local SlotNum2 = 15
- if turtle.getFuelLevel()<100 then
- if turtle.getItemCount(15)>0 then
- turtle.select(15)
- turtle.refuel()
- turtle.select(1)
- elseif turtle.getItemCount(15)==0 then
- if turtle.getItemCount(16)>0 then
- turtle.select(16)
- turtle.refuel()
- turtle.select(1)
- elseif turtle.getItemCount(16)==0 then
- turtle.select(15)
- if bit.band(TurtleYPoss, 1) == 0 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- for j=1,(TurtleYPosss-1) do
- turtle.forward()
- end
- turtle.turnLeft()
- for g=1,(TurtleXPosss-1) do
- turtle.forward()
- end
- turtle.up()
- turtle.select(15)
- if turtle.suck() == true then
- turtle.refuel(32)
- turtle.select(16)
- turtle.suck()
- turtle.refuel(32)
- else
- turtle.select(16)
- if turtle.suck() == true and turtle.refuel(32) == true then
- turtle.refuel(32)
- else
- turtle.select(15)
- print("Turtle is out of fuel. Please input fuel into the chest/turtle.")
- repeat
- sleep(1)
- until turtle.refuel() == true or turtle.suck() == true and turtle.refuel(32)
- turtle.refuel(32)
- turtle.select(1)
- end
- end
- turtle.down()
- turtle.turnRight()
- turtle.turnRight()
- for h=1,TurtleXPos-1 do
- turtle.forward()
- end
- turtle.turnRight()
- for k=1,TurtleYPos-1 do
- turtle.forward()
- end
- if bit.band(TurtleYPoss, 2) == 0 then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- end
- turtle.select(1)
- end
- end
- function doDelay()
- for l=1,Delay do
- sleep(60)
- end
- end
- function checkFull()
- local ResourceSlotCount = SeedSlotAmount + 1
- local q
- local j
- local g
- local p
- local l
- local h
- local k
- local SlotNum = 2
- local SlotNum2 = ResourceSlotCount
- local TurtleXPoss = TurtleXPos
- local TurtleYPoss = TurtleYPos
- local TurtleXPosss = TurtleXPos
- local TurtleYPosss = TurtleYPos
- for q=2,14 do
- if SlotNum2>14 then
- SlotNum2 = 14
- end
- if turtle.getItemCount(SlotNum2)==64 then
- repeat
- SlotNum2=SlotNum2+1
- local itemCount=turtle.getItemCount(SlotNum2)
- until itemCount<64 or SlotNum2 == 15
- turtle.select(1)
- elseif SlotNum2==15 and turtle.getItemCount==64 then
- if bit.band(TurtleYPoss, 2) == 0 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- for j=1,TurtleYPoss-1 do
- turtle.forward()
- end
- turtle.turnLeft()
- for g=1,TurtleXPoss-1 do
- turtle.forward()
- end
- for l=ResourceSlotCount,13 do
- turtle.select(SlotNum)
- turtle.drop()
- SlotNum=SlotNum+1
- end
- turtle.turnRight()
- turtle.turnRight()
- for h=1,TurtleXPosss-1 do
- turtle.forward()
- end
- turtle.turnRight()
- for k=1,TurtleYPosss-1 do
- turtle.forward()
- end
- if bit.band(TurtleYPoss, 2) == 0 then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- ResourceSlotCount=SeedSlotAmount+1
- turtle.select(1)
- end
- end
- end
- function goHome()
- local TurtleXPoss = TurtleXPos
- local TurtleYPoss = TurtleYPos
- local TurtleXPosss = TurtleXPos
- local TurtleYPosss = TurtleYPos
- local q
- local p
- local h
- local SlotNum = SeedSlotAmount+1
- local b
- local SlotNum2 = 2
- if bit.band(TurtleYPoss, 1) == 0 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- for q=1,TurtleYPosss-1 do
- turtle.forward()
- end
- turtle.turnLeft()
- for p=1,TurtleXPosss-1 do
- turtle.forward()
- end
- if FirstRun==true then
- for h=SeedSlotAmount,14 do
- turtle.select(SlotNum)
- turtle.drop(64)
- SlotNum=SlotNum+1
- if SlotNum==15 then
- SlotNum=1
- end
- end
- else
- for b=2,14 do
- turtle.select(SlotNum2)
- turtle.drop(64)
- SlotNum2=SlotNum2+1
- if SlotNum2==15 then
- SlotNum2=1
- end
- end
- end
- turtle.select(15)
- turtle.up()
- turtle.suck(64)
- turtle.refuel()
- turtle.select(16)
- turtle.suck(64)
- turtle.refuel()
- turtle.select(1)
- turtle.down()
- turtle.turnRight()
- turtle.turnRight()
- end
- function lengthSpan()
- local p
- for LengthLoop = 1,Length-1 do
- if FirstRun == false then
- checkFull()
- else
- checkSeedCount()
- end
- doRefuel()
- turtle.digDown()
- turtle.placeDown()
- turtle.forward()
- if changeXPos == false then
- TurtleXPos = TurtleXPos+1
- print("Debug: TurtleXPos: "..TurtleXPos)
- elseif changeXPos == true then
- TurtleXPos = TurtleXPos-1
- print("Debug: TurtleXPos: "..TurtleXPos)
- end
- end
- end
- function nextRow()
- if turnLeft == false then
- turtle.turnRight()
- turtle.digDown()
- turtle.placeDown()
- turtle.forward()
- turtle.turnRight()
- turnLeft = true
- TurtleYPos = TurtleYPos + 1
- print(TurtleYPos)
- elseif turnLeft == true then
- turtle.turnLeft()
- turtle.digDown()
- turtle.placeDown()
- turtle.forward()
- turtle.turnLeft()
- turnLeft = false
- TurtleYPos = TurtleYPos+1
- print(TurtleYPos)
- end
- end
- function harvestLand()
- local q
- local l
- local slotNum=1
- checkFirst()
- for q=1,Width do
- lengthSpan()
- nextRow()
- changeReverseXPos()
- end
- goHome()
- doDelay()
- if FirstRun==true then
- FirstRun=false
- end
- end
- while true do
- harvestLand()
- end
Add Comment
Please, Sign In to add comment