Advertisement
exa-byte

AgriCraftCropEnhancer v1.00

Aug 17th, 2016
944
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.33 KB | None | 0 0
  1. -------------------------------------
  2. -- AgriCraftCropBreeder by ExaByte --
  3. -------------------------------------
  4.  
  5. fuelSlot = 1
  6. bonemealSlot = 2
  7. analyzerSlot = 3
  8. cropStickSlot = 4
  9. fruitSlot = 5
  10. bestSeedSlot = 16
  11. analyzerSide = nil -- where the analyzer can find crops
  12.  
  13. useBonemealOnParents = true
  14. useBonemealOnCrossCrops = false
  15. bestSeedStats = {}
  16. nextBestSeedStats = {}
  17.  
  18. -- movement
  19. function u()
  20.     while not turtle.up() do refuel()sleep(1) end
  21. end
  22. function f()
  23.     while not turtle.forward() do refuel()sleep(1) end
  24. end
  25. function d()
  26.     while not turtle.down() do refuel()sleep(1) end
  27. end
  28. function b()
  29.     while not turtle.back() do refuel()sleep(1) end
  30. end
  31. function l()
  32.     turtle.turnLeft()
  33. end
  34. function r()
  35.     turtle.turnRight()
  36. end
  37. function place(slotOrName)
  38.     select(slotOrName)
  39.     while not turtle.place() do sleep(1) end
  40. end
  41. function placeDown(slotOrName)
  42.     select(slotOrName)
  43.     while not turtle.placeDown() do sleep(1) end
  44. end
  45. function placeUp(slotOrName)
  46.     select(slotOrName)
  47.     while not turtle.placeUp() do sleep(1) end
  48. end
  49.  
  50. -- inventory management
  51.  
  52. -- count item
  53. function countItem(itemName)
  54.     local count = 0
  55.     for i = 1,16 do
  56.         local data = turtle.getItemDetail(i)
  57.         if data then
  58.             if data.name == itemName then
  59.                 count = count + data.count
  60.             end
  61.         end
  62.     end
  63.     return count
  64. end
  65.  
  66. -- time efficient slot selection
  67. function selectSlot(num)
  68.     if (turtle.getSelectedSlot() ~= num) then
  69.         turtle.select(num)
  70.     end
  71. end
  72.  
  73. function select(itemNameOrSlot)
  74.     if type(itemNameOrSlot) == "number" then
  75.         if not (turtle.getSelectedSlot() == itemNameOrSlot) then
  76.             turtle.select(itemNameOrSlot)
  77.         end
  78.     elseif itemNameOrSlot == "emptySlot" then
  79.         local found = false
  80.         for i = 1,16 do
  81.             if turtle.getItemCount(i) == 0 then
  82.                 turtle.select(i)
  83.                 found = true
  84.                 break
  85.             end
  86.         end
  87.         if not found then
  88.             error("select(\"emptySlot\"): no empty slot found!")
  89.         end
  90.     else
  91.         local data = turtle.getItemDetail()
  92.         if data then
  93.             if data.name == itemNameOrSlot then
  94.                 return
  95.             end
  96.         end
  97.         local found = false
  98.         for i = 1, 16, 1 do  
  99.             data = turtle.getItemDetail(i)
  100.             if data then
  101.                 if data.name == itemNameOrSlot then
  102.                     turtle.select(i)
  103.                     found = true
  104.                     break
  105.                 end
  106.             end
  107.         end
  108.         if not found then
  109.             print("could not find item of type \"" .. itemNameOrSlot .. "\" - please insert!")
  110.             while found == false do
  111.                 local data
  112.                 -- local found = false
  113.                 for i = 1, 16, 1 do
  114.                     data = turtle.getItemDetail(i)
  115.                     if data then
  116.                         if data.name == itemNameOrSlot then
  117.                             turtle.select(i)
  118.                             found = true
  119.                             break
  120.                         end
  121.                     end            
  122.                 end
  123.                 sleep (2)
  124.             end
  125.             print("thanks for the supplies!")
  126.         end
  127.     end
  128. end
  129.  
  130. -- fuel management
  131.  
  132. -- on the go refuel
  133. function refuel()
  134.     local wasNoFuel = false
  135.     while (turtle.getFuelLevel() < 1) do
  136.         for i = 1, 16 do
  137.             if turtle.getItemCount(i) > 0 then
  138.                 turtle.select(i)
  139.                 if turtle.refuel(0) then
  140.                     turtle.refuel()
  141.                 end
  142.             end
  143.         end
  144.         if (turtle.getFuelLevel() < 1) then
  145.             print("no fuel! please insert some!")
  146.             wasNoFuel = true
  147.         end
  148.     end
  149.     if (wasNoFuel) then
  150.         print("refueled")
  151.     end
  152. end
  153.  
  154. -- check for fuel
  155. function checkGetFuel()
  156.     local fuelLevel = turtle.getFuelLevel()
  157.     if (fuelLevel <= 512) then
  158.         refuel() -- refuel from inventory
  159.         if (fuelLevel <= 512) then
  160.             print("low on fuel (less than 512): taking some from chest...")
  161.             l()
  162.             select("emptySlot")
  163.             local written = false
  164.             while (turtle.suck() == false) do
  165.                 if not written then
  166.                     written = true
  167.                     print("fuel chest is now empty, please refill")
  168.                 end
  169.                 sleep(1)
  170.             end
  171.             turtle.refuel()
  172.             r()
  173.         end
  174.     end
  175. end
  176.  
  177. -- find analyzer in inventory
  178. function findAnalyzer()
  179.     select("AgriCraft:peripheral")
  180. end
  181.  
  182. -- wrap computer controlled seed analyzer on bottom
  183. function connectAnalyzer(dir)
  184.     analyzer = peripheral.wrap(dir)
  185.     while (not analyzer) do
  186.         analyzer = peripheral.wrap(dir)
  187.         if (not analyzer) then
  188.             print("Could not find computer controlled seed analyzer on side <" .. dir .. ">! Please place it there!")
  189.             sleep(1)
  190.         end
  191.     end
  192. end
  193.  
  194. -- get bonemeal from chest to the right
  195. function getBonemeal()
  196.     local toGet = 64 - turtle.getItemCount(bonemealSlot)
  197.     r()
  198.     selectSlot(bonemealSlot)
  199.     local written = false
  200.     while (not turtle.suck(toGet)) or (turtle.getItemCount(bonemealSlot) <= 1) do
  201.         if not written then
  202.             written = true
  203.             print("bonemeal chest is empty, please refill")
  204.         end
  205.         sleep(1)
  206.     end
  207.     l()
  208. end
  209.  
  210. -- determine analyzerSide
  211. function determineAnalyzerSide()
  212.     b()
  213.     place("AgriCraft:peripheral")
  214.     connectAnalyzer("front")
  215.     while (analyzerSide == nil) do
  216.         if pcall(function ()analyzer.hasPlant("NORTH")end) then
  217.             analyzerSide = "NORTH"
  218.         elseif pcall(function ()analyzer.hasPlant("EAST")end) then
  219.             analyzerSide = "EAST"
  220.         elseif pcall(function ()analyzer.hasPlant("SOUTH")end) then
  221.             analyzerSide = "SOUTH"
  222.         elseif pcall(function ()analyzer.hasPlant("WEST")end) then
  223.             analyzerSide = "WEST"
  224.         else
  225.             print("Error while determining analyzerSide, there must be crop sticks next to the seed analyzer")
  226.             sleep (1)
  227.         end
  228.     end
  229.     turtle.dig()
  230.     f()
  231. end
  232.  
  233. -- use the seed analyzer to check whether the seed grew
  234. function checkSeedGrew()
  235.     b()
  236.     place("AgriCraft:peripheral")
  237.     connectAnalyzer("front")
  238.  
  239.     --[[if analyzerSide == nil then
  240.         determineAnalyzerSide()
  241.     end]]
  242.    
  243.     local seedGrew = analyzer.hasPlant(analyzerSide)
  244.     turtle.dig()
  245.     f()
  246.     return seedGrew
  247. end
  248.  
  249. -- make sure turtle has at least 2 crop sticks to start with
  250. function checkCropSticks()
  251.     local written = false
  252.     local data = turtle.getItemDetail(4)
  253.    
  254.     while true do
  255.         data = turtle.getItemDetail(4)
  256.         if data then
  257.             -- if crop sticks present, break
  258.             if (data.name == "AgriCraft:cropsItem" and data.count >= 2) then
  259.                 break
  260.             end
  261.         end
  262.         if not written then
  263.             print("please insert initial 3 (or more) crop sticks in slot 4")
  264.             written = true
  265.         end
  266.         sleep(1)
  267.     end
  268. end
  269.  
  270. -- bonemeal parent crop until fully grown
  271. function bonemealParent()
  272.     -- only do this if useBonemealOnParents flag is set to true
  273.     if useBonemealOnParents then
  274.         local mature = false
  275.         while not mature do
  276.             local success, data = turtle.inspectDown()
  277.             if success then
  278.                 if data.metadata == 7 then
  279.                     mature = true
  280.                 else
  281.                     placeDown(bonemealSlot)
  282.                 end
  283.             end
  284.         end
  285.     end
  286. end
  287.  
  288. -- analyzes farmed seeds and throws bad ones away
  289. function analyzeSeeds(dir) 
  290.     placeUp("AgriCraft:peripheral")
  291.     connectAnalyzer("top")
  292.     local aSlot = turtle.getSelectedSlot()
  293.     local data
  294.     for i = 1,16 do
  295.         data = turtle.getItemDetail(i)
  296.         if data then
  297.             if string.find(data.name, "seed") then
  298.                 -- case: this item name contains "AgriCraft:seed"
  299.                 selectSlot(i)
  300.                 turtle.dropUp()
  301.                
  302.                 -- analyze seeds
  303.                 while not analyzer.isAnalyzed() do
  304.                     analyzer.analyze()
  305.                     sleep(0.2)
  306.                 end
  307.                 local stats = { analyzer.getSpecimenStats() }
  308.                 if (    ( stats[1] == 10 or stats[1] >= bestSeedStats[1] + 1 )
  309.                     and ( stats[2] == 10 or stats[2] >= bestSeedStats[2] + 1 )
  310.                     and ( stats[3] == 10 or stats[3] >= bestSeedStats[3] + 1 )) then
  311.                     -- set nextBestSeedStats to this
  312.                     nextBestSeedStats = { stats[1], stats[2], stats[3] }
  313.                     -- best possible crop for this iteration reached, transfer to bestSeedSlot
  314.                     selectSlot(bestSeedSlot)
  315.                     turtle.suckUp()
  316.                     -- if there are more than 2 seeds in slot, transfer exceeding to old slot
  317.                     if (turtle.getItemCount(bestSeedSlot) > 2) then
  318.                         turtle.transferTo(i, turtle.getItemCount(bestSeedSlot)-2)
  319.                     end
  320.                 else
  321.                     -- suck this damn unworthy seed
  322.                     turtle.suckUp()
  323.                 end
  324.             end
  325.         end
  326.     end
  327.     -- break analyzer
  328.     select(aSlot)
  329.     turtle.digUp()
  330.     return stats
  331. end
  332.  
  333. -- dumps unworthy seeds to an inventory below the starting place
  334. function dumpSeeds()
  335.     local data
  336.     for i = 1,15 do
  337.         data = turtle.getItemDetail(i)
  338.         if data then
  339.             if string.find(data.name, "seed") then
  340.                 -- case: this item name contains "AgriCraft:seed"
  341.                 selectSlot(i)
  342.                 turtle.dropDown()
  343.             end
  344.         end
  345.     end
  346. end
  347.  
  348. -- place analyzer down and use it to watch growth stage
  349. function checkParentGrowthWithAnalyzer()
  350.     if not useBonemealOnParents then
  351.         -- local table for analyzer directions for plant stats
  352.         local dir1, dir2
  353.         if analyzerSide     == "WEST"   then dir1 = "NORTH";    dir2 = "EAST"
  354.         elseif analyzerSide == "NORTH"  then dir1 = "EAST";     dir2 = "SOUTH"
  355.         elseif analyzerSide == "EAST"   then dir1 = "SOUTH";    dir2 = "WEST"
  356.         elseif analyzerSide == "SOUTH"  then dir1 = "WEST";     dir2 = "NORTH"
  357.         end
  358.        
  359.         placeDown("AgriCraft:peripheral")
  360.         connectAnalyzer("bottom")
  361.        
  362.         print("waiting for parent plants to grow fully")
  363.         while not (analyzer.isMature(dir1) and analyzer.isMature(dir2)) do
  364.             sleep(2)
  365.         end
  366.         print("parent plants fully grown...")
  367.        
  368.         turtle.digDown()
  369.     end
  370. end
  371.  
  372. -- grow new seeds with bonemeal and break them
  373. function growBreakSeeds()
  374.     local success, data = turtle.inspect()
  375.     -- wait until there are crop sticks placed
  376.     local msec = 1
  377.     while not success do
  378.         success, data = turtle.inspect()
  379.         -- check interval increments up to 2s
  380.         sleep(math.min(msec/1000, 2000))
  381.         msec = msec*2
  382.     end
  383.     if success then
  384.         if useBonemealOnCrossCrops then
  385.             repeat
  386.                 -- get bonemeal when needed
  387.                 if turtle.getItemCount(bonemealSlot) <= 1 then
  388.                     getBonemeal()
  389.                 end
  390.                 selectSlot(bonemealSlot)
  391.                 turtle.place()         
  392.             until checkSeedGrew()
  393.         else
  394.             -- use analyzer to wait for new seeds to grow
  395.             b()
  396.             place("AgriCraft:peripheral")
  397.             connectAnalyzer("front")
  398.             while not pcall (function() analyzer.hasPlant(analyzerSide) end) do
  399.                 print("the autonomous activator might be out of crop sticks, please refill")
  400.                 sleep(2)
  401.             end
  402.             local written = false
  403.             while not analyzer.hasPlant(analyzerSide) do
  404.                 if not written then
  405.                     print("waiting for seed to grow")
  406.                     written = true
  407.                 end
  408.                 sleep(1)
  409.             end
  410.             -- get analyzer
  411.             turtle.dig()
  412.             f()
  413.         end
  414.         -- dig seed up
  415.         select(cropStickSlot)
  416.         turtle.dig()
  417.     end
  418. end
  419.  
  420. -- uses analyzer to get stats of already planted parent seeds
  421. function getParentStats()
  422.     -- local table for analyzer directions for plant stats
  423.     local dir1, dir2
  424.     if analyzerSide     == "WEST"   then dir1 = "NORTH";    dir2 = "EAST"
  425.     elseif analyzerSide == "NORTH"  then dir1 = "EAST";     dir2 = "SOUTH"
  426.     elseif analyzerSide == "EAST"   then dir1 = "SOUTH";    dir2 = "WEST"
  427.     elseif analyzerSide == "SOUTH"  then dir1 = "WEST";     dir2 = "NORTH"
  428.     end
  429.    
  430.     placeDown("AgriCraft:peripheral")
  431.     connectAnalyzer("bottom")
  432.    
  433.     local stats = { analyzer.getSpecimenStats(dir2) }
  434.    
  435.     turtle.digDown()
  436.    
  437.     return stats
  438. end
  439.  
  440. -- place analyzer in direction <dir> and get the seed stats from selected slot, put these in <stats> (table) [usage: local stats = getSeedStats(dir, slot);
  441. function getSeedStats(dir, slot)
  442.     -- place analyzer
  443.     if dir == "top" then
  444.         placeUp("AgriCraft:peripheral")
  445.     elseif dir == "front" then
  446.         place("AgriCraft:peripheral")
  447.     elseif dir == "bottom" then
  448.         placeDown("AgriCraft:peripheral")  
  449.     else
  450.         print("Error: getSeedStats(dir, stats) doesn't accept <" .. dir .. "> as dir!") return
  451.     end
  452.     local lyzerSlot = turtle.getSelectedSlot()
  453.     connectAnalyzer(dir)
  454.     selectSlot(slot)
  455.     if dir == "top" then
  456.         turtle.dropUp()
  457.     elseif dir == "front" then
  458.         turtle.drop()
  459.     elseif dir == "bottom" then
  460.         turtle.dropDown()
  461.     end
  462.     while not analyzer.isAnalyzed() do
  463.         analyzer.analyze()
  464.         sleep(0.2)
  465.     end
  466.     local s1,s2,s3 = analyzer.getSpecimenStats()
  467.     local stats = { s1,s2,s3 }
  468.     -- retrieve seeds from analyzer, then get the analyzer itself
  469.     if dir == "top" then
  470.         turtle.suckUp()
  471.     elseif dir == "front" then
  472.         turtle.suck()
  473.     elseif dir == "bottom" then
  474.         turtle.suckDown()
  475.     end
  476.     select(lyzerSlot)
  477.     if dir == "top" then
  478.         turtle.digUp()
  479.     elseif dir == "front" then
  480.         turtle.dig()
  481.     elseif dir == "bottom" then
  482.         turtle.digDown()
  483.     end
  484.     return stats
  485. end
  486.  
  487. -- unloadsFruits
  488. function checkUnoadFruits()
  489.     local limitReached = false
  490.     for i = 1,16 do
  491.         local data = turtle.getItemDetail(i)
  492.         if data then
  493.             if not (    data.name == "AgriCraft:peripheral" or
  494.                         data.name == "AgriCraft:cropsItem" or
  495.                        (data.name == "minecraft:dye" and data.damage == 15) or
  496.                         string.find(data.name, "seed")) then
  497.                 -- all that is in turtle inventory and not covered by this list above is considered a fruit
  498.                 --if turtle.getItemSpace(i) < 3 then -- removed for clearing every time
  499.                     limitReached = true
  500.                     break
  501.                 --end
  502.             end
  503.         end
  504.     end
  505.     if limitReached then
  506.         b()
  507.         for i = 1,16 do
  508.             -- if one is to much dump all
  509.             if limitReached then
  510.                 data = turtle.getItemDetail(i)
  511.                 if data then
  512.                     if not (    data.name == "AgriCraft:peripheral" or
  513.                                 data.name == "AgriCraft:cropsItem" or
  514.                                (data.name == "minecraft:dye" and data.damage == 15) or
  515.                                 string.find(data.name, "seed")) then
  516.                         -- all that is in turtle inventory and not covered by this list above is considered a fruit
  517.                         select(i)
  518.                         while not turtle.dropDown() do sleep(1) end
  519.                     end
  520.                 end
  521.             end
  522.         end
  523.         f()
  524.     end
  525. end
  526.  
  527. -- check unload cropSticks
  528. function checkUnloadCropSticks()
  529.     local count = countItem("AgriCraft:cropsItem")
  530.     if (count >= 52) then
  531.         -- goto unload point1
  532.         u()f()r()f()
  533.         -- select last slot with crop sticks in it
  534.         local data
  535.         local continue = true
  536.         local goToNextUnload = false
  537.         while countItem("AgriCraft:cropsItem") > 3 and continue do
  538.             for i = 16,1,-1 do
  539.                 data = turtle.getItemDetail(i)
  540.                 if data then
  541.                     if data.name == "AgriCraft:cropsItem" then
  542.                         selectSlot(i)
  543.                         if not (turtle.dropDown(math.max(math.min(64, count-3)), 0)) then
  544.                             -- turtle couldn't unlaod stuff anymore ( autonomous activator inventory is full )
  545.                             goToNextUnload = true
  546.                             continue = false
  547.                             break
  548.                         end
  549.                         count = countItem("AgriCraft:cropsItem")
  550.                     end
  551.                 end
  552.             end
  553.         end
  554.         if goToNextUnload then
  555.             -- turtle must unload at unload spot 2:
  556.             -- goto unload point2
  557.             l()f()
  558.             while countItem("AgriCraft:cropsItem") > 3 do
  559.                 for i = 16,1,-1 do
  560.                     data = turtle.getItemDetail(i)
  561.                     if data then
  562.                         if data.name == "AgriCraft:cropsItem" then
  563.                             selectSlot(i)
  564.                             while not (turtle.dropDown(math.max(math.min(64, count-3)), 0)) do
  565.                                 -- turtle couldn't unlaod stuff anymore ( unload spot 2 is full )
  566.                                 sleep(1)
  567.                             end
  568.                             count = countItem("AgriCraft:cropsItem")
  569.                         end
  570.                     end
  571.                 end
  572.             end
  573.             b()r()
  574.         end
  575.         -- go back
  576.         b()l()b()d()
  577.     end
  578. end
  579.  
  580. -- selects a slot that contains a seed with the specified stats by using a on top placed analyzer
  581. function selectSeedWithStats(dstats)
  582.     placeUp("AgriCraft:peripheral")
  583.     connectAnalyzer("top")
  584.     local aSlot = turtle.getSelectedSlot()
  585.     local data
  586.     local sSlot
  587.     for i = 1,16 do
  588.         data = turtle.getItemDetail(i)
  589.         if data then
  590.             if string.find(data.name, "seed") then
  591.                 -- case: this item name contains "AgriCraft:seed"
  592.                 selectSlot(i)
  593.                 turtle.dropUp()
  594.                
  595.                 -- analyze seeds
  596.                 while not analyzer.isAnalyzed() do
  597.                     analyzer.analyze()
  598.                     sleep(0.2)
  599.                 end
  600.                 local stats = { analyzer.getSpecimenStats() }
  601.                 if (stats[1] == dstats[1] and stats[2] == dstats[2] and stats[3] == dstats[3]) then
  602.                     turtle.suckUp()
  603.                     sSlot = i
  604.                     break
  605.                 else
  606.                     -- suck this damn unworthy seed
  607.                     turtle.suckUp()
  608.                 end
  609.             end
  610.         end
  611.     end
  612.     -- break analyzer
  613.     select(aSlot)
  614.     turtle.digUp()
  615.     if sSlot ~= nil then
  616.         select(sSlot)
  617.     end
  618. end
  619.  
  620. -- replaces old parents with better new ones
  621. function replaceParents()
  622.     getBonemeal()
  623.     u()f()l()f()
  624.     -- replace old first parent with fresh crop sticks
  625.     select(cropStickSlot)
  626.     turtle.digDown()
  627.     placeDown(cropStickSlot)
  628.     b()r()f()
  629.     -- replace old first parent with fresh crop sticks
  630.     turtle.digDown()
  631.     placeDown(cropStickSlot)
  632.     b()
  633.     -- break old middle plant
  634.     select(cropStickSlot)
  635.     turtle.digDown()
  636.     l()f()f()
  637.     select(bestSeedSlot)
  638.     -- plant the first parent
  639.     turtle.dropDown(1)
  640.     redstone.setOutput("bottom", true)
  641.     sleep(1)
  642.     redstone.setOutput("bottom", false)
  643.     b()
  644.     bonemealParent()
  645.     -- grow second parent from first
  646.     b()r()b()d()
  647.     -- this should give 1 seed
  648.     growBreakSeeds()
  649.     -- this puts the 2nd parent into slot 16
  650.     selectSeedWithStats(bestSeedStats) 
  651.     u()f()f()f()
  652.     -- plant the 2nd parent
  653.     turtle.dropDown(1)
  654.     redstone.setOutput("bottom", true)
  655.     sleep(1)
  656.     redstone.setOutput("bottom", false)
  657.     b()
  658.     bonemealParent()
  659.     if not useBonemealOnParents then
  660.         l()f()
  661.         checkParentGrowthWithAnalyzer()
  662.         b()r()
  663.     end
  664.     b()b()d()  
  665. end
  666.  
  667. -- check initial plants and place and grow them when there are none, also use analyzer on them to get stats
  668. function checkInitialPlants()
  669.     u()f()l()f()
  670.     local numCropSticksNeeded = 0
  671.     -- check if theres already a crop planted
  672.     if not turtle.detectDown() then
  673.         -- case: no plant present
  674.         if countItem("AgriCraft:cropsItem") >= 1 then
  675.             r()
  676.             -- get best seed stats from analyzer
  677.             bestSeedStats = getSeedStats("front", bestSeedSlot)
  678.             l()b()r()b()d()
  679.             replaceParents()
  680.         else
  681.             print("now broken: needed crop sticks, had none")
  682.         end
  683.        
  684.     else
  685.         -- case: plant present
  686.         r()f()l()
  687.         local stats = getParentStats()
  688.         bestSeedStats = { stats[1], stats[2], stats[3] }
  689.         b()r()b()b()d()
  690.     end
  691. end
  692.  
  693. -- breaks remaining plants after 10 10 10 crop reached and dumps them into chest
  694. function clearFieldAndInventory()
  695. checkUnloadCropSticks()
  696.     u()f()l()f()
  697.     selectSlot(cropStickSlot)
  698.     turtle.digDown()
  699.     b()r()f()
  700.     turtle.digDown()
  701.     b()
  702.     turtle.digDown()
  703.     b()d()
  704.     dumpSeeds()
  705.     checkUnoadFruits()
  706. end
  707.  
  708. -- unloads 10 10 10 seed in inventory 1 back and 1 left from starting point
  709. function unloadBestSeed()
  710.     u()l()
  711.     selectSlot(bestSeedSlot)
  712.     local written = false
  713.     while not turtle.drop() do
  714.         if not written then
  715.             print("inventory on front is full... waiting")
  716.         end
  717.         sleep(1)
  718.     end
  719.     r()d()
  720. end
  721.  
  722. -- gets a new seed to enhance from inventory 1 back and 1 left from starting point
  723. function pickUpNewSeed()
  724.     u()r()
  725.     selectSlot(bestSeedSlot)
  726.     local written = false
  727.     print("turtle.suck()")
  728.     while not turtle.suck() do
  729.         if not written then
  730.             print("waiting for new seed in inventory to the front")
  731.         end
  732.         sleep(1)
  733.     end
  734.     l()d()
  735. end
  736.  
  737. ----------
  738. -- main --
  739. ----------
  740.  
  741.  
  742.  
  743. checkGetFuel()
  744. checkCropSticks()
  745. findAnalyzer()
  746. determineAnalyzerSide()
  747. checkInitialPlants()
  748. analyzeSeeds()
  749. dumpSeeds()
  750. while true do
  751.     while not (nextBestSeedStats[1] == 10 and nextBestSeedStats[2] == 10 and nextBestSeedStats[3] == 10 and turtle.getItemCount(bestSeedSlot) == 1) do
  752.         while (not (turtle.getItemCount(bestSeedSlot) == 1)) do
  753.             growBreakSeeds()
  754.             analyzeSeeds()
  755.             dumpSeeds()
  756.         end
  757.         checkUnoadFruits()
  758.         checkUnloadCropSticks()
  759.         checkGetFuel()
  760.         if not (nextBestSeedStats[1] == 10 and nextBestSeedStats[2] == 10 and nextBestSeedStats[3] == 10 and turtle.getItemCount(bestSeedSlot) == 1) then
  761.             bestSeedStats = nextBestSeedStats
  762.             getBonemeal()
  763.             replaceParents()
  764.         end
  765.     end
  766.     clearFieldAndInventory()
  767.     unloadBestSeed()
  768.     print("finished: got 10 10 10 seed in chest")
  769.     pickUpNewSeed()
  770.     bestSeedStats = getSeedStats("top", bestSeedSlot)
  771.     nextBestSeedStats = { math.min(bestSeedStats[1]+1, 10), math.min(bestSeedStats[2]+1, 10), math.min(bestSeedStats[3]+1, 10) }
  772.     print("bestSeedStats = "..bestSeedStats[1]..bestSeedStats[2]..bestSeedStats[3])
  773.     print("nextBestSeedStats = "..nextBestSeedStats[1]..nextBestSeedStats[2]..nextBestSeedStats[3])
  774.     replaceParents()
  775. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement