Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Made by Rnen10
- -- If problems/questions feel free to contact me
- -- https://twitter.com/Rnen10
- -- rnen. (Evan#7181) on discord
- --Here is a detailed view
- --https://imgur.com/a/FMfTi
- --Here's a flowchart showing how it works
- --https://sketchboard.me/NAZDv63LNgBd#/
- --Use this for automatic updates-> pastebin get fehTMGPp startup
- -- =============VARIABLES===================
- analyzer = peripheral.wrap("bottom")
- --Plant 1 & 2
- local p1 = nil
- local p2 = nil
- --Seeds in analyzer
- local p3 = nil
- --Variable for when job is done
- local done = false
- local plantName = nil
- function DEBUG()
- return fs.exists("seeddebug")
- end
- local posData = { ["x"] = 0, ["y"] = 0, ["rot"] = 1 }
- -- ============VARIABLES END================
- -- ============FUNCTIONS====================
- function NewLine(Str)
- local barLength = 40
- local tempPercentage = 0
- term.clear()
- term.setCursorPos(1,2)
- print("-------------[SeedBot v3.8]------------")
- term.setCursorPos(11,5)
- write("v {Current action} v")
- term.setCursorPos(21 - (math.floor(string.len(Str) / 2)),8)
- print(Str)
- if not plantName == nil then
- plantString = "Current Type: "..plantName
- term.setCursorPos(20 - (math.floor(string.len(plantString) / 2)),9)
- print(plantString)
- end
- if DEBUG() then
- term.setCursorPos(1,11)
- print("X: "..posData["x"].." Y: "..posData["y"].." Rot: "..posData["rot"])
- end
- term.setCursorPos(12,12)
- write("[Current Fuel %"..(math.floor(turtle.getFuelLevel())))
- write("]")
- term.setCursorPos(1,13)
- barLength = turtle.getFuelLevel() / 100 * 40
- if barLength > 40 then barLength = 40 end
- if term.isColor() then
- term.setBackgroundColor(colors.green)
- else
- term.setBackgroundColor(colors.white)
- end
- for i =1,(barLength) do
- write(" ")
- end
- if barLength < 40 then
- if term.isColor() then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.gray) end
- local remainingBarLength = (40 - barLength)
- for i =1,(remainingBarLength) do
- write(" ")
- end
- end
- term.setBackgroundColor(colors.black)
- end
- function ClearSeeds()
- analyzer = peripheral.wrap("bottom")
- if analyzer.hasPlant("NORTH") then
- Left()
- Forward()
- turtle.select(1)
- turtle.digDown()
- turtle.suckDown()
- turtle.select(1)
- turtle.placeDown()
- Back()
- Right()
- end
- if analyzer.hasPlant("EAST") then
- Forward()
- turtle.select(1)
- turtle.digDown()
- turtle.suckDown()
- turtle.select(1)
- turtle.placeDown()
- Back()
- end
- Empty()
- end
- function Empty()
- if not done then NewLine("Emptying Inventory") end
- for i = 1,16 do
- turtle.select(i)
- if not turtle.dropUp() and (turtle.getItemCount()>0) then
- NewLine("Chest is full!")
- done = true
- break
- end
- end
- turtle.select(1)
- end
- function CheckSeeds()
- analyzer = peripheral.wrap("bottom")
- if analyzer.hasPlant("NORTH") == true and analyzer.hasPlant("EAST") == true then
- local s1, s2, s3 = analyzer.getSpecimenStats("NORTH")
- p1 = s1 + s2 + s3
- local s1, s2, s3 = analyzer.getSpecimenStats("EAST")
- p2 = s1 + s2 + s3
- if p1==30 or p2==30 then
- GetNewSeeds()
- end
- else
- GetNewSeeds()
- return
- end
- end
- function DuplicateSingleSeed()
- if analyzer.hasPlant("NORTH") or analyzer.hasPlant("EAST") then
- Empty()
- os.reboot()
- else
- NewLine("Analyzing single Seed")
- turtle.select(1)
- analyzer = peripheral.wrap("bottom")
- turtle.dropDown(turtle.getItemCount())
- analyzer.analyze()
- while not analyzer.isAnalyzed() do
- sleep(1)
- end
- plantName = analyzer.getSpecimen()
- NewLine("Planting single seed")
- turtle.suckDown()
- Forward()
- Right()
- Forward()
- redstone.setOutput("bottom", true)
- while turtle.getItemCount() > 0 do turtle.dropDown(1) end
- sleep(2)
- redstone.setOutput("bottom", false)
- Back()
- Back()
- Left()
- Forward()
- redstone.setOutput("bottom", true)
- sleep(0.9)
- redstone.setOutput("bottom", false)
- Back()
- Right()
- Back()
- NewLine("Waiting for seed to duplicate...")
- while analyzer.isCrossCrop("SOUTH") do
- sleep(5)
- end
- NewLine("Picking up new seed")
- Forward()
- turtle.select(1)
- turtle.digDown()
- turtle.suckDown()
- turtle.placeDown()
- Forward()
- Left()
- Back()
- turtle.select(2)
- analyzer = peripheral.wrap("bottom")
- turtle.dropDown(turtle.getItemCount())
- analyzer.analyze()
- sleep(3.5)
- turtle.suckDown()
- Left()
- Forward()
- Forward()
- redstone.setOutput("bottom", true)
- turtle.dropDown(1)
- sleep(2)
- redstone.setOutput("bottom", false)
- Back()
- Back()
- Right()
- Empty()
- os.reboot()
- end
- end
- function GetNewSeeds()
- plantName = nil
- NewLine("Changing out seeds")
- if p1 == nil or p2 == nil then
- p1 = 1
- p2 = 1
- elseif p1>p2 then
- Left()
- Forward()
- turtle.select(1)
- turtle.digDown()
- turtle.suckDown()
- turtle.select(1)
- turtle.placeDown()
- Back()
- Right()
- Forward()
- Empty()
- turtle.select(1)
- turtle.digDown()
- turtle.suckDown()
- turtle.select(1)
- turtle.placeDown()
- Back()
- Empty()
- elseif p1<p2 then
- Left()
- Forward()
- turtle.select(1)
- turtle.digDown()
- turtle.suckDown()
- turtle.select(1)
- turtle.placeDown()
- Back()
- Right()
- Empty()
- Forward()
- turtle.select(1)
- turtle.digDown()
- turtle.suckDown()
- turtle.select(1)
- turtle.placeDown()
- Empty()
- Back()
- else
- ClearSeeds()
- Empty()
- end
- Right()
- if turtle.suck() then
- Left()
- if turtle.getItemCount() == 1 then
- --Empty()
- --os.reboot()
- DuplicateSingleSeed()
- end
- analyzer = peripheral.wrap("bottom")
- turtle.dropDown(turtle.getItemCount())
- analyzer.analyze()
- NewLine("Analyzing new seeds")
- while not analyzer.isAnalyzed() do
- sleep(1)
- end
- plantName = analyzer.getSpecimen()
- turtle.select(2)
- turtle.suckDown()
- NewLine("Planting new seeds")
- Forward()
- Right()
- Forward()
- redstone.setOutput("bottom", true)
- turtle.dropDown(1)
- sleep(2)
- redstone.setOutput("bottom", false)
- Back()
- Left()
- Back()
- Left()
- Forward()
- Forward()
- redstone.setOutput("bottom", true)
- turtle.dropDown(1)
- sleep(2)
- redstone.setOutput("bottom", false)
- Back()
- Back()
- Right()
- Empty()
- CheckSeeds()
- else
- Left()
- NewLine("Done!")
- done = true
- ClearSeeds()
- return
- end
- CheckSeeds()
- end
- function CheckFuel(bool)
- local fuel = turtle.getFuelLevel()
- --Checking fuel level & fueling if low
- if turtle.getFuelLevel() < 25 then
- GetFuel()
- return true
- else
- return false
- end
- end
- function GetFuel()
- if not done then NewLine("Getting fuel") end
- --print("Current Fuel Level: "..turtle.getFuelLevel())
- Left()
- Left()
- turtle.select(16)
- while turtle.getFuelLevel() <= 100 do
- if not turtle.suck(1) and (turtle.getFuelLevel() <= 100) then
- NewLine("No fuel in fuel chest!")
- turtle.select(1)
- done = true
- break
- end
- turtle.refuel(1)
- turtle.drop(turtle.getItemCount(16))
- NewLine("Getting fuel")
- --print("Current Fuel Level: "..turtle.getFuelLevel())
- end
- turtle.select(1)
- Right()
- Right()
- end
- function CheckEmpty()
- local invItemNumber = 0
- NewLine("Counting Items...")
- for i = 1,16 do
- turtle.select(i)
- invItemNumber = invItemNumber + turtle.getItemCount(i)
- end
- if invItemNumber > 0 then
- NewLine("Not empty! Resetting")
- turtle.select(1)
- return false
- else
- turtle.select(1)
- return true
- end
- end
- function CheckPosition()
- if fs.exists("seedPos") then
- local file = fs.open("seedPos","r")
- local data = file.readAll()
- file.close()
- posData = textutils.unserialize(data)
- else
- local file = fs.open("seedPos","w")
- file.write(textutils.serialize(posData))
- file.close()
- end
- end
- function SavePosition()
- local file = fs.open("seedPos","w")
- file.write(textutils.serialize(posData))
- file.close()
- end
- function Forward()
- turtle.forward()
- if posData["rot"] == 1 then
- posData["x"] = posData["x"] + 1
- elseif posData["rot"] == 3 then
- posData["x"] = posData["x"] - 1
- elseif posData["rot"] == 0 then
- posData["y"] = posData["y"] - 1
- elseif posData["rot"] == 2 then
- posData["y"] = posData["y"] + 1
- end
- SavePosition()
- end
- function Right()
- turtle.turnRight()
- posData["rot"] = posData["rot"] + 1
- if posData["rot"] > 4 then posData["rot"] = 0 end
- SavePosition()
- end
- function Left()
- turtle.turnLeft()
- posData["rot"] = posData["rot"] - 1
- if posData["rot"] < 0 then posData["rot"] = 4 end
- SavePosition()
- end
- function Back()
- turtle.back()
- if posData["rot"] == 1 then
- posData["x"] = posData["x"] - 1
- elseif posData["rot"] == 3 then
- posData["x"] = posData["x"] + 1
- elseif posData["rot"] == 0 then
- posData["y"] = posData["y"] + 1
- elseif posData["rot"] == 2 then
- posData["y"] = posData["y"] - 1
- end
- SavePosition()
- end
- -- ===========STARTUP SEQUENCE==========
- if turtle.getFuelLevel() > 4 then CheckPosition() end
- CheckFuel()
- -- ===========STARTUP SEQUENCE END======
- -- ===========MAIN LOOP=================
- while not done do
- --Sleep to prevent timeout
- --sleep(1)
- p1Mature = analyzer.isMature("EAST")
- p2Mature = analyzer.isMature("NORTH")
- if p1Mature and p2Mature then
- NewLine("Going to cross-crop activator")
- --Place 2nd crop stick for crossbreeding
- Forward()
- Left()
- Forward()
- Right()
- Forward()
- redstone.setOutput("bottom", true)
- sleep(0.8)
- redstone.setOutput("bottom", false)
- NewLine("Moving to second Analyzer")
- Back()
- Right()
- if turtle.suckDown() then
- Forward()
- Left()
- Back()
- Empty()
- os.reboot()
- else
- Back()
- end
- NewLine("Waiting for new seed")
- analyzer = peripheral.wrap("bottom")
- if not analyzer.hasPlant("SOUTH") and not analyzer.isCrossCrop("SOUTH") then
- NewLine("No cross crop sticks, resetting")
- Forward()
- Forward()
- Left()
- Back()
- os.reboot()
- else
- while analyzer.isCrossCrop("SOUTH") do
- sleep(5)
- end
- end
- NewLine("Picking up new seed")
- Forward()
- turtle.select(1)
- turtle.digDown()
- turtle.suckDown()
- turtle.placeDown()
- NewLine("Going to Analyzer 1")
- turtle.select(2)
- Forward()
- Left()
- Back()
- sleep(0.1)
- if CheckEmpty() then os.reboot() else turtle.select(2) end
- NewLine("Analyzing new seed")
- analyzer = peripheral.wrap("bottom")
- turtle.dropDown(turtle.getItemCount())
- analyzer.analyze()
- while not analyzer.isAnalyzed() do
- sleep(3.5)
- end
- local s1, s2, s3 = analyzer.getSpecimenStats()
- p3 = s1 + s2 + s3
- if p3 == 30 then
- turtle.suckDown()
- Forward()
- Empty()
- Back()
- p1=nil
- p2=nil
- ClearSeeds()
- --return
- else
- turtle.select(2)
- turtle.suckDown()
- NewLine("Removing weakest seed")
- CheckSeeds()
- if p1<=p2 then
- Left()
- Forward()
- turtle.select(1)
- turtle.digDown()
- turtle.suckDown()
- turtle.select(1)
- turtle.placeDown()
- Forward()
- redstone.setOutput("bottom", true)
- turtle.select(2)
- turtle.dropDown(1)
- sleep(2)
- redstone.setOutput("bottom", false)
- Back()
- Back()
- Right()
- Empty()
- else
- Forward()
- turtle.select(1)
- turtle.digDown()
- turtle.suckDown()
- Right()
- turtle.select(1)
- turtle.placeDown()
- Forward()
- redstone.setOutput("bottom", true)
- turtle.select(2)
- turtle.dropDown(1)
- sleep(2)
- redstone.setOutput("bottom", false)
- Back()
- Left()
- Back()
- Empty()
- end
- end
- end
- CheckSeeds()
- if not done then
- NewLine("Waiting for growth")
- if not CheckFuel() then sleep(5) end
- end
- end
- -- ================Main Loop End=========================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement