SHARE
TWEET

Agricraft Seed Breeder

Rnen10 Jun 4th, 2016 (edited) 2,626 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Made by Rnen10
  2. --If problems/questions feel free to contact me
  3. --https://twitter.com/Rnen10
  4. --Evan#7181  on discord
  5.  
  6. --Here is a detailed view
  7. --https://imgur.com/a/FMfTi
  8.  
  9. --Here's a flowchart showing how it works
  10. --https://sketchboard.me/NAZDv63LNgBd#/
  11.  
  12.  
  13. --Use this for automatic updates->  pastebin get fehTMGPp startup
  14.  
  15. -- =============VARIABLES===================
  16. analyzer = peripheral.wrap("bottom")
  17.  
  18. --Plant 1 & 2
  19. local p1 = nil
  20. local p2 = nil
  21. --Seeds in analyzer
  22. local p3 = nil
  23. --Variable for when job is done
  24. local done = false
  25. -- ============VARIABLES END================
  26.  
  27. -- ============FUNCTIONS====================
  28. function NewLine(Str,Int)
  29.     local barLength = 40
  30.     local tempPercentage = 0
  31.     term.clear()
  32.     term.setCursorPos(1,2)
  33.     print("-------------[SeedBot v3.6]------------")
  34.     term.setCursorPos(11,5)
  35.     write("v {Current action} v")
  36.     term.setCursorPos(Int,8)
  37.     print(Str)
  38.     term.setCursorPos(12,12)
  39.     write("[Current Fuel %"..(math.floor(turtle.getFuelLevel())))
  40.     write("]")
  41.     term.setCursorPos(1,13)
  42.     barLength = turtle.getFuelLevel() / 100 * 40
  43.     if barLength > 40 then barLength = 40 end
  44.     if term.isColor() then
  45.       term.setBackgroundColor(colors.green)
  46.     else
  47.       term.setBackgroundColor(colors.white)
  48.     end
  49.     for i =1,(barLength) do
  50.       write(" ")
  51.     end
  52.     if barLength < 40 then
  53.         if term.isColor() then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.gray) end
  54.         local remainingBarLength = (40 - barLength)
  55.         for i =1,(remainingBarLength) do
  56.           write(" ")
  57.         end
  58.     end
  59.     term.setBackgroundColor(colors.black)
  60. end
  61.  
  62. function ClearSeeds()
  63.     turtle.turnLeft()
  64.     turtle.forward()
  65.     turtle.select(1)
  66.     turtle.digDown()
  67.     turtle.suckDown()
  68.     turtle.select(1)
  69.     turtle.placeDown()
  70.     turtle.back()
  71.     turtle.turnRight()
  72.     turtle.forward()
  73.     turtle.select(1)
  74.     turtle.digDown()
  75.     turtle.suckDown()
  76.     turtle.select(1)
  77.     turtle.placeDown()
  78.     turtle.back()
  79.     Empty()
  80. end
  81.  
  82. function Empty()
  83.     if not done then NewLine("Emptying Inventory",12) end
  84.     for i = 1,16 do
  85.       turtle.select(i)
  86.       if not turtle.dropUp() and (turtle.getItemCount()>0) then
  87.         NewLine("Chest is full!",14)
  88.         done = true
  89.         break
  90.       end
  91.     end
  92.     turtle.select(1)
  93. end
  94.  
  95. function CheckSeeds()
  96.   analyzer = peripheral.wrap("bottom")
  97.   if analyzer.hasPlant("NORTH") == true and analyzer.hasPlant("EAST") == true then
  98.     local s1, s2, s3 = analyzer.getSpecimenStats("NORTH")
  99.     p1 = s1 + s2 + s3
  100.     local s1, s2, s3 = analyzer.getSpecimenStats("EAST")
  101.     p2 = s1 + s2 + s3
  102.     if p1==30 or p2==30 then
  103.       GetNewSeeds()
  104.     end
  105.   else
  106.     GetNewSeeds()
  107.     return
  108.   end
  109. end
  110.  
  111. function DuplicateSingleSeed()
  112.     if analyzer.hasPlant("NORTH") or analyzer.hasPlant("EAST") then
  113.         Empty()
  114.         os.reboot()
  115.     else
  116.         NewLine("Duplicating single Seed",9)
  117.         turtle.select(1)
  118.         analyzer = peripheral.wrap("bottom")
  119.         turtle.dropDown(turtle.getItemCount())
  120.         analyzer.analyze()
  121.         sleep(3.5)
  122.         turtle.suckDown()
  123.         turtle.forward()
  124.         turtle.turnRight()
  125.         turtle.forward()
  126.         redstone.setOutput("bottom", true)
  127.         turtle.dropDown(1)
  128.         sleep(2)
  129.         redstone.setOutput("bottom", false)
  130.         turtle.back()
  131.         turtle.back()
  132.         turtle.turnLeft()
  133.         turtle.forward()
  134.         redstone.setOutput("bottom", true)
  135.         sleep(0.9)
  136.         redstone.setOutput("bottom", false)
  137.         turtle.back()
  138.         turtle.turnRight()
  139.         turtle.back()
  140.         while analyzer.isCrossCrop("SOUTH") do
  141.             sleep(5)
  142.         end
  143.         turtle.forward()
  144.         turtle.select(1)
  145.         turtle.digDown()
  146.         turtle.suckDown()
  147.         turtle.placeDown()
  148.         turtle.forward()
  149.         turtle.turnLeft()
  150.         turtle.back()
  151.         turtle.select(2)
  152.         analyzer = peripheral.wrap("bottom")
  153.         turtle.dropDown(turtle.getItemCount())
  154.         analyzer.analyze()
  155.         sleep(3.5)
  156.         turtle.suckDown()
  157.         turtle.turnLeft()
  158.         turtle.forward()
  159.         turtle.forward()
  160.         redstone.setOutput("bottom", true)
  161.         turtle.dropDown(1)
  162.         sleep(2)
  163.         redstone.setOutput("bottom", false)
  164.         turtle.back()
  165.         turtle.back()
  166.         turtle.turnRight()
  167.         Empty()
  168.         os.reboot()
  169.     end
  170. end
  171.  
  172. function GetNewSeeds()
  173.     NewLine("Changing out seeds",12)
  174.     if p1 == nil or p2 == nil then
  175.         p1 = 1
  176.         p2 = 1
  177.     elseif p1>p2 then
  178.         turtle.turnLeft()
  179.         turtle.forward()
  180.         turtle.select(1)
  181.         turtle.digDown()
  182.         turtle.suckDown()
  183.         turtle.select(1)
  184.         turtle.placeDown()
  185.         turtle.back()
  186.         turtle.turnRight()
  187.         turtle.forward()
  188.         Empty()
  189.         turtle.select(1)
  190.         turtle.digDown()
  191.         turtle.suckDown()
  192.         turtle.select(1)
  193.         turtle.placeDown()
  194.         turtle.back()
  195.         Empty()
  196.     elseif p1<p2 then
  197.         turtle.turnLeft()
  198.         turtle.forward()
  199.         turtle.select(1)
  200.         turtle.digDown()
  201.         turtle.suckDown()
  202.         turtle.select(1)
  203.         turtle.placeDown()
  204.         turtle.back()
  205.         turtle.turnRight()
  206.         Empty()
  207.         turtle.forward()
  208.         turtle.select(1)
  209.         turtle.digDown()
  210.         turtle.suckDown()
  211.         turtle.select(1)
  212.         turtle.placeDown()
  213.         Empty()
  214.         turtle.back()
  215.     else
  216.         turtle.turnLeft()
  217.         turtle.forward()
  218.         turtle.select(1)
  219.         turtle.digDown()
  220.         turtle.suckDown()
  221.         turtle.select(1)
  222.         turtle.placeDown()
  223.         turtle.back()
  224.         turtle.turnRight()
  225.         turtle.forward()
  226.         turtle.select(1)
  227.         turtle.digDown()
  228.         turtle.suckDown()
  229.         turtle.select(1)
  230.         turtle.placeDown()
  231.         turtle.back()
  232.         Empty()
  233.     end
  234.     turtle.turnRight()
  235.     if turtle.suck() then
  236.       turtle.turnLeft()
  237.       if turtle.getItemCount() == 1 then
  238.         --Empty()
  239.         --os.reboot()
  240.         DuplicateSingleSeed()
  241.       end
  242.       analyzer = peripheral.wrap("bottom")
  243.       turtle.dropDown(turtle.getItemCount())    
  244.       analyzer.analyze()
  245.       NewLine("Analyzing new seeds",12)
  246.       sleep(3.5)
  247.       turtle.select(2)
  248.       turtle.suckDown()
  249.  
  250.       NewLine("Planting new seeds",12)
  251.  
  252.       turtle.forward()
  253.       turtle.turnRight()
  254.       turtle.forward()
  255.       redstone.setOutput("bottom", true)
  256.       turtle.dropDown(1)
  257.       sleep(2)
  258.       redstone.setOutput("bottom", false)
  259.       turtle.back()
  260.       turtle.turnLeft()
  261.       turtle.back()
  262.       turtle.turnLeft()
  263.       turtle.forward()
  264.       turtle.forward()
  265.       redstone.setOutput("bottom", true)
  266.       turtle.dropDown(1)
  267.       sleep(2)
  268.       redstone.setOutput("bottom", false)
  269.       turtle.back()
  270.       turtle.back()
  271.       turtle.turnRight()
  272.       Empty()
  273.       CheckSeeds()
  274.     else
  275.       turtle.turnLeft()
  276.       NewLine("Done!",19)
  277.       done = true
  278.       ClearSeeds()
  279.       return
  280.     end
  281.     CheckSeeds()
  282. end
  283.  
  284. function CheckFuel(bool)
  285.   local fuel = turtle.getFuelLevel()
  286.   --Checking fuel level & fueling if low
  287.   if turtle.getFuelLevel() < 25 then
  288.     GetFuel()
  289.     return true
  290.   else
  291.   return false
  292.   end
  293. end
  294.  
  295. function GetFuel()
  296.   if not done then NewLine("Getting fuel",15) end
  297.   --print("Current Fuel Level: "..turtle.getFuelLevel())
  298.   turtle.turnLeft()
  299.   turtle.turnLeft()
  300.   turtle.select(16)
  301.   while turtle.getFuelLevel() <= 100 do
  302.     if not turtle.suck(1) and (turtle.getFuelLevel() <= 100) then
  303.       NewLine("No fuel in fuel chest!",10)
  304.       turtle.select(1)
  305.       done = true
  306.       break
  307.     end
  308.     turtle.refuel(1)
  309.     turtle.drop(turtle.getItemCount(16))
  310.     NewLine("Getting fuel",15)
  311.     --print("Current Fuel Level: "..turtle.getFuelLevel())
  312.   end
  313.   turtle.select(1)
  314.   turtle.turnRight()
  315.   turtle.turnRight()
  316. end
  317.  
  318. function CheckEmpty(bool)
  319.   local invItemNumber = 0
  320.   NewLine("Counting Items...",13)
  321.   for i = 1,16 do
  322.     turtle.select(i)
  323.     invItemNumber = invItemNumber + turtle.getItemCount(i)
  324.   end
  325.   if invItemNumber > 0 then
  326.     NewLine("Not empty! Resetting",11)
  327.     turtle.select(1)
  328.     return false
  329.   else
  330.     turtle.select(1)
  331.     return true
  332.   end
  333. end
  334.  
  335. function CheckPosition()
  336.   if turtle.up() then
  337.     NewLine("Returning to start position",8)
  338.     turtle.down()
  339.     turtle.forward()
  340.     turtle.forward()
  341.     turtle.turnLeft()
  342.     turtle.back()
  343.     os.reboot()
  344.   end
  345. end
  346.  
  347.  
  348. -- ===========STARTUP SEQUENCE==========
  349. if turtle.getFuelLevel() > 4 then CheckPosition() end
  350. CheckFuel()
  351. -- ===========STARTUP SEQUENCE END======
  352.  
  353. -- ===========MAIN LOOP=================
  354. while not done do
  355.   --Sleep to prevent timeout
  356.   --sleep(1)
  357.  
  358.   p1Mature = analyzer.isMature("EAST")
  359.   p2Mature = analyzer.isMature("NORTH")
  360.  
  361.   if p1Mature and p2Mature then
  362.     NewLine("Going to stick-activator",9)
  363.  
  364.     --Place 2nd crop stick for crossbreeding
  365.     turtle.forward()
  366.     turtle.turnLeft()
  367.     turtle.forward()
  368.     turtle.turnRight()
  369.     turtle.forward()
  370.     redstone.setOutput("bottom", true)
  371.     sleep(0.9)
  372.     redstone.setOutput("bottom", false)
  373.    
  374.     NewLine("Moving to second Analyzer",9)
  375.  
  376.     turtle.back()
  377.     turtle.turnRight()
  378.     if turtle.suckDown() then
  379.       turtle.forward()
  380.       turtle.turnLeft()
  381.       turtle.back()
  382.       Empty()
  383.       os.reboot()
  384.     else
  385.       turtle.back()
  386.     end
  387.  
  388.    
  389.     NewLine("Waiting for new seed",11)
  390.  
  391.     analyzer = peripheral.wrap("bottom")
  392.     if not analyzer.hasPlant("SOUTH") and not analyzer.isCrossCrop("SOUTH") then
  393.       NewLine("No cross crop sticks, resetting",6)
  394.       turtle.forward()
  395.       turtle.forward()
  396.       turtle.turnLeft()
  397.       turtle.back()
  398.       os.reboot()
  399.     else
  400.       while analyzer.isCrossCrop("SOUTH") do
  401.         sleep(5)
  402.       end
  403.     end
  404.     NewLine("Getting new seed",13) 
  405.  
  406.     turtle.forward()
  407.     turtle.select(1)
  408.     turtle.digDown()
  409.     turtle.suckDown()
  410.     turtle.placeDown()
  411.  
  412.     NewLine("Going to Analyzer 1",12)
  413.  
  414.     turtle.select(2)
  415.     turtle.forward()
  416.     turtle.turnLeft()
  417.     turtle.back()
  418.     sleep(0.1)
  419.  
  420.     if CheckEmpty() then os.reboot() else turtle.select(2) end
  421.     NewLine("Analyzing new seed",12)
  422.  
  423.     analyzer = peripheral.wrap("bottom")
  424.     turtle.dropDown(turtle.getItemCount())    
  425.     analyzer.analyze()
  426.     sleep(3.5)
  427.     local s1, s2, s3 = analyzer.getSpecimenStats()
  428.     p3 = s1 + s2 + s3
  429.     if p3 == 30 then
  430.       turtle.suckDown()
  431.       turtle.forward()
  432.       Empty()
  433.       turtle.back()
  434.       p1=nil
  435.       p2=nil
  436.       ClearSeeds()
  437.       --return
  438.     else
  439.       turtle.select(2)
  440.       turtle.suckDown()
  441.  
  442.       NewLine("Removing weakest seed",11)
  443.  
  444.       CheckSeeds()
  445.       if p1<=p2 then
  446.         turtle.turnLeft()
  447.         turtle.forward()
  448.         turtle.select(1)
  449.         turtle.digDown()
  450.         turtle.suckDown()
  451.         turtle.select(1)
  452.         turtle.placeDown()
  453.         turtle.forward()
  454.         redstone.setOutput("bottom", true)
  455.         turtle.select(2)
  456.         turtle.dropDown(1)
  457.         sleep(2)
  458.         redstone.setOutput("bottom", false)
  459.         turtle.back()
  460.         turtle.back()
  461.         turtle.turnRight()
  462.         Empty()
  463.       else
  464.         turtle.forward()
  465.         turtle.select(1)
  466.         turtle.digDown()
  467.         turtle.suckDown()
  468.         turtle.turnRight()
  469.         turtle.select(1)
  470.         turtle.placeDown()
  471.         turtle.forward()
  472.         redstone.setOutput("bottom", true)
  473.         turtle.select(2)
  474.         turtle.dropDown(1)
  475.         sleep(2)
  476.         redstone.setOutput("bottom", false)
  477.         turtle.back()
  478.         turtle.turnLeft()
  479.         turtle.back()
  480.         Empty()
  481.       end
  482.     end
  483.   end
  484.   CheckSeeds()
  485.   if not done then
  486.  NewLine("Waiting for growth",12)
  487.   if not CheckFuel() then sleep(5) end
  488.  end
  489. end
  490. -- ================Main Loop End=========================
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top