galygious

Breed

Feb 22nd, 2020
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.12 KB | None | 0 0
  1. chickenslot = 15
  2. chicken1 = 9
  3. chicken2 = 10
  4. seedslot = 14
  5. chickens = 0
  6. maintenanceround = 0
  7. breeddir = 'u' -- dirctions include ('u','d','f')
  8. seeddir = 'd' -- dirctions include ('u','d','f')
  9. trashdir = 'f' -- dirctions include ('u','d','f')
  10. breederpd = 'w' -- the direction that you palced the breeder. only used if wrapping breeder to the front.
  11. breedbox = 'roost:breeder'
  12. trashbox = 'cyclicmagic:trash'
  13. seedbox = 'yabba:item_barrel'
  14.  
  15. function seedaction(action)
  16.     if action == 'place' then
  17.         if seeddir == 'd' then
  18.             turtle.placeDown()
  19.         elseif seeddir == 'f' then
  20.             turtle.place()
  21.         elseif seeddir == 'u' then
  22.             turtle.placeUp()
  23.         end
  24.     elseif action == 'break' then
  25.         if seeddir == 'd' then
  26.             turtle.digDown()
  27.         elseif seeddir == 'f' then
  28.             turtle.dig()
  29.         elseif seeddir == 'u' then
  30.             turtle.digUp()
  31.         end
  32.     elseif action == 'pull' then
  33.         if seeddir == 'd' then
  34.             if not turtle.suckDown() then
  35.                 print("Out of seeds")
  36.                 error()
  37.             end
  38.         elseif seeddir == 'f' then
  39.             if not turtle.suck() then
  40.                 print("Out of seeds")
  41.                 error()
  42.             end
  43.         elseif seeddir == 'u' then
  44.             if not turtle.suckUp() then
  45.                 print("Out of seeds")
  46.                 error()
  47.             end
  48.         end
  49.     elseif action == 'push' then
  50.         if seeddir == 'd' then
  51.             turtle.dropDown()
  52.         elseif seeddir == 'f' then
  53.             turtle.drop()
  54.         elseif seeddir == 'u' then
  55.             turtle.dropUp()
  56.         end
  57.     elseif action == 'setup' then
  58.         if seeddir ~= 'd' and seeddir ~= 'f' and seeddir ~= 'u' then
  59.             print("seeddir is set incorrectly.")
  60.             error()
  61.         else
  62.             if seeddir == 'd' then
  63.                 stupid, seedcheck = turtle.inspectDown()
  64.             elseif seeddir == 'f' then
  65.                 stupid, seedcheck = turtle.inspect()
  66.             else
  67.                 stupid, seedcheck = turtle.inspectUp()
  68.             end
  69.             if seedcheck ~= nil then
  70.                 if seedcheck.name ~= seedbox then
  71.                     seedboxthere = false
  72.                 else
  73.                     seedboxthere = true
  74.                 end
  75.             else
  76.                 print("error with seedcheck")
  77.             end
  78.         end
  79.     else
  80.         print('error function seedaction(action), action was unknown')
  81.         error()
  82.     end
  83. end
  84.  
  85. function breedaction(action,fromslot,cap,toslot)
  86.     if action == 'place' then
  87.         if breeddir == 'd' then
  88.             turtle.placeDown()
  89.             breeder = peripheral.wrap("down")
  90.             fromname = 'up'
  91.         elseif breeddir == 'f' then
  92.             turtle.place()
  93.             breeder = peripheral.wrap("front")
  94.             if breederpd == 'w' then
  95.                 fromname = 'east'
  96.             elseif breederpd == 'e' then
  97.                 fromname = 'west'
  98.             elseif breederpd == 's' then
  99.                 fromname = 'north'
  100.             elseif breederpd == 'n' then
  101.                 fromname = 'south'
  102.             else
  103.                 print("breederpd or breeddir is not set correctly in the config")
  104.                 error()
  105.             end
  106.         elseif breeddir == 'u' then
  107.             turtle.placeUp()
  108.             breeder = peripheral.wrap("top")
  109.             fromname = 'down'
  110.         end
  111.     elseif action == 'break' then
  112.         if breeddir == 'd' then
  113.             turtle.digDown()
  114.         elseif breeddir == 'f' then
  115.             turtle.dig()
  116.         elseif breeddir == 'u' then
  117.             turtle.digUp()
  118.         end
  119.     elseif action == 'pull' then
  120.             breeder.pushItems(fromname,fromslot,cap,toslot)
  121.     elseif action == 'push' then
  122.             breeder.pullItems(fromname,fromslot,cap,toslot)
  123.     elseif action == 'setup' then
  124.         if breeddir ~= 'd' and breeddir ~= 'f' and breeddir ~= 'u' then
  125.             print("breeddir is set incorrectly.")
  126.             error()
  127.         else
  128.             if breeddir == 'd' then
  129.                 stupid, breedcheck = turtle.inspectDown()
  130.             elseif breeddir == 'f' then
  131.                 stupid, breedcheck = turtle.inspect()
  132.             else
  133.                 stupid, breedcheck = turtle.inspectUp()
  134.             end
  135.             if breedcheck.name ~= breedbox then
  136.                 breedboxthere = false
  137.             else
  138.                 if breeddir == 'u' then
  139.                     breeder = peripheral.wrap("top")
  140.                     fromname = 'down'
  141.                 elseif breeddir == 'f' then
  142.                     breeder = peripheral.wrap("front")
  143.                     if breederpd == 'w' then
  144.                         fromname = 'east'
  145.                     elseif breederpd == 'e' then
  146.                         fromname = 'west'
  147.                     elseif breederpd == 's' then
  148.                         fromname = 'north'
  149.                     elseif breederpd == 'n' then
  150.                         fromname = 'south'
  151.                     else
  152.                         print("breederpd or breeddir is not set correctly in the config")
  153.                         error()
  154.                     end
  155.                 elseif breeddir == 'd' then
  156.                     breeder = peripheral.wrap("down")
  157.                     fromname = 'up'
  158.                 end
  159.                 breedboxthere = true
  160.             end
  161.         end
  162.     else
  163.         print('error function breedaction(action), action was unknown')
  164.         error()
  165.     end
  166.     do return end
  167. end
  168.  
  169. function trashaction(action)
  170.     if action == 'place' then
  171.         if trashdir == 'd' then
  172.             turtle.placeDown()
  173.         elseif trashdir == 'f' then
  174.             turtle.place()
  175.         elseif trashdir == 'u' then
  176.             turtle.placeUp()
  177.         end
  178.     elseif action == 'break' then
  179.         if trashdir == 'd' then
  180.             turtle.digDown()
  181.         elseif trashdir == 'f' then
  182.             turtle.dig()
  183.         elseif trashdir == 'u' then
  184.             turtle.digUp()
  185.         end
  186.     elseif action == 'push' then
  187.         if trashdir == 'd' then
  188.             turtle.dropDown()
  189.         elseif trashdir == 'f' then
  190.             turtle.drop()
  191.         elseif trashdir == 'u' then
  192.             turtle.dropUp()
  193.         end
  194.     elseif action == 'setup' then
  195.         if trashdir ~= 'd' and trashdir ~= 'f' and trashdir ~= 'u' then
  196.             print("trashdir is set incorrectly.")
  197.             error()
  198.         else
  199.             if trashdir == 'd' then
  200.                 stupid, trashcheck = turtle.inspectDown()
  201.             elseif trashdir == 'f' then
  202.                 stupid, trashcheck = turtle.inspect()
  203.             else
  204.                 stupid, trashcheck = turtle.Up()
  205.             end
  206.             if trashcheck ~= nil then
  207.                 if trashcheck.name == trashbox then
  208.                     trashboxthere = true
  209.                 end
  210.             end
  211.         end
  212.     else
  213.         print('error function trashaction(action), action was unknown')
  214.         error()
  215.     end
  216. end
  217.  
  218. function getseeds()
  219.     turtle.select(seedslot)
  220.     seedaction("pull")
  221. end
  222.  
  223. function fillseeds()
  224.     if breeddir == 'd' then
  225.         breeder.pullItems('up',seedslot,64,3)
  226.     elseif breeddir == 'f' then
  227.         breeder.pullItems(fromname,seedslot,64,3)
  228.     elseif breeddir == 'u' then
  229.         breeder.pullItems('down',seedslot,64,3)
  230.     else
  231.         print("please fix the breeder location in the config")
  232.         error()
  233.     end
  234.     turtle.select(seedslot)
  235.     seedaction("push")
  236.     do return end
  237. end
  238.  
  239. function program()
  240.     turtle.select(chickenslot)
  241.     if maintenanceround < 16 then
  242.         while not turtle.suckUp() do
  243.             term.clear()
  244.             term.setCursorPos(1,1)
  245.             print("I'm waiting for chickens")
  246.             sleep(1)
  247.         end
  248.         count()
  249.     else
  250.         if breeder.getItemMeta(6) ~= nil then
  251.             while breeder.getItemMeta(6).count < 16 do
  252.                 term.clear()
  253.                 term.setCursorPos(1,1)
  254.                 print("I'm waiting for the 10 10 10 chickens to finish breeding")
  255.                 sleep(1)
  256.             end
  257.             print("Finished Breeding")
  258.             error()
  259.         else
  260.             sleep(1)
  261.             getseeds()
  262.             fillseeds()
  263.             program()
  264.         end
  265.     end
  266.     do return end
  267. end
  268.  
  269. function count()
  270.     if chickens == 0 then
  271.         turtle.transferTo(chicken1)
  272.         chickens = chickens + 1
  273.         print("I got one")
  274.     elseif chickens == 1 then
  275.         print("I have 2 chickens")
  276.         turtle.transferTo(chicken2)
  277.         chickens = 0
  278.         reset()
  279.     end
  280.     program()
  281. end
  282.  
  283. function reset()
  284.     if maintenance == true then
  285.         if maintenanceround < 16 then
  286.             breedaction('push',chicken1,16,1)
  287.             breedaction('push',chicken2,16,2)
  288.             getseeds()
  289.             fillseeds()
  290.         end
  291.         maintenanceround = maintenanceround + 1
  292.     else
  293.         breedaction('pull',1,16,1)
  294.         breedaction('pull',2,16,2)
  295.         turtle.select(1)
  296.         trashaction('push')
  297.         turtle.select(2)
  298.         trashaction('push')
  299.         breedaction('push',chicken1,16,1)
  300.         breedaction('push',chicken2,16,2)
  301.         chicken1stats = breeder.getItemMeta(1).roost
  302.         chicken2stats = breeder.getItemMeta(2).roost
  303.         if chicken1stats.gain == 10 and chicken2stats.gain == 10 and chicken1stats.growth == 10 and chicken2stats.growth == 10 and chicken1stats.strength == 10 and chicken2stats.strength == 10 then
  304.             print("Im now breeding 2 tens")
  305.             maintenance = true
  306.             maintenanceround = 1
  307.         else
  308.             print("chicken 1 gain |" .. chicken1stats.gain)
  309.             print("chicken 1 growth |" .. chicken1stats.growth)
  310.             print("chicken 1 strength |" .. chicken1stats.strength)
  311.             print("chicken 2 gain |" .. chicken2stats.gain)
  312.             print("chicken 2 growth |" .. chicken2stats.growth)
  313.             print("chicken 2 strength |" .. chicken2stats.strength)
  314.         end
  315.         getseeds()
  316.         fillseeds()
  317.     end
  318. end
  319.  
  320. function start()
  321.     chickcount = 0
  322.     trashboxthere = false
  323.     seedboxthere = false
  324.     trashactionthere = false
  325.     breedaction('setup')
  326.     seedaction('setup')
  327.     trashaction('setup')
  328.     nostart = false
  329.     for c=1,16 do
  330.         if nostart == false then
  331.             turtle.select(c)
  332.             if turtle.getItemDetail(c) ~= nil then
  333.                 sloti = turtle.getItemDetail(c)
  334.                 if sloti.name == 'roost:chicken' then
  335.                     if  chickcount == 0 then
  336.                         oslot1 = c
  337.                         chickcount = chickcount + 1
  338.                     elseif chickcount == 1 then
  339.                         oslot2 = c
  340.                         chickcount = chickcount + 1
  341.                     elseif chickcount >1 then
  342.                         print("there are too many chickens in the inventory")
  343.                         error()
  344.                     end
  345.                 elseif sloti.name == 'minecraft:wheat_seeds' then
  346.                     if seedboxthere == true then
  347.                         seedaction('push')
  348.                     else
  349.                         foundseedbox = false
  350.                         for k=1,16 do
  351.                             if turtle.getItemDetail(k) ~= nil then
  352.                                 seedboxfinder = turtle.getItemDetail(k)
  353.                                 if seedboxfinder.name == seedbox then
  354.                                     seedaction('place')
  355.                                     foundseedbox = true
  356.                                 end
  357.                             end
  358.                         end
  359.                         if foundseedbox == false then
  360.                             print("could not find " .. seedbox)
  361.                             error()
  362.                         end
  363.                     end
  364.                 elseif sloti.name == breedbox then
  365.                     if breedboxthere == false then
  366.                         breedaction('place')
  367.                         breedboxthere = true
  368.                     else
  369.                         turtle.turnRight()
  370.                         turtle.turnRight()
  371.                         turtle.drop()
  372.                         turtle.turnRight()
  373.                         turtle.turnRight()
  374.                     end
  375.                 elseif sloti.name == trashbox then
  376.                     if trashboxthere == false then
  377.                         trashaction('place')
  378.                         trashboxthere = true
  379.                     else
  380.                         print(trashboxthere)
  381.                         turtle.turnRight()
  382.                         turtle.turnRight()
  383.                         turtle.drop()
  384.                         turtle.turnRight()
  385.                         turtle.turnRight()                     
  386.                     end
  387.                 elseif sloti.name == seedbox then
  388.                     if seedboxthere == false then
  389.                         seedaction('place')
  390.                         seedboxthere = true
  391.                     else
  392.                         turtle.turnRight()
  393.                         turtle.turnRight()
  394.                         turtle.drop()
  395.                         turtle.turnRight()
  396.                         turtle.turnRight()                     
  397.                     end
  398.                 else
  399.                     turtle.turnRight()
  400.                     turtle.turnRight()
  401.                     turtle.drop()
  402.                     turtle.turnRight()
  403.                     turtle.turnRight() 
  404.                 end
  405.             end
  406.         end
  407.     end
  408.     if chickcount < 2 then
  409.         enoughchickens = false
  410.         if oslot1 ~= nil then
  411.             if turtle.getItemCount(oslot1) > 1 then
  412.                 enoughchickens = true
  413.                 turtle.select(oslot1)
  414.                 if turtle.getItemCount(oslot1) % 2 == 0 then
  415.                     if oslot1 == 16 then
  416.                         turtle.transferTo((oslot1-1),(turtle.getItemCount(oslot1)/2))
  417.                         oslot2 = oslot1-1
  418.                     else
  419.                         turtle.transferTo((oslot1+1),(turtle.getItemCount(oslot1)/2))
  420.                         oslot2 = oslot1+1
  421.                     end
  422.                 else
  423.                     if oslot1 == 16 then
  424.                         turtle.transferTo((oslot1-1),((turtle.getItemCount(oslot1)-1)/2))
  425.                         oslot2 = oslot1-1
  426.                     else
  427.                         turtle.transferTo((oslot1+1),((turtle.getItemCount(oslot1)-1)/2))
  428.                         oslot2 = oslot1+1
  429.                     end                
  430.                 end
  431.             end
  432.         end
  433.         if enoughchickens == false then
  434.             more = false
  435.             if breeder.getItemMeta(1) ~= nil then
  436.                 if breeder.getItemMeta(1).name == "roost:chicken" then
  437.                     for i=1,16 do
  438.                         turtle.select(i)
  439.                         if turtle.getItemDetail() == nil then
  440.                             breedaction('pull',1,16,i)
  441.                             more = true
  442.                         end
  443.                     end
  444.                 end
  445.             end
  446.             if breeder.getItemMeta(2) ~= nil then
  447.                 if breeder.getItemMeta(2).name == "roost:chicken" then
  448.                     for i=1,16 do
  449.                         turtle.select(i)
  450.                         if turtle.getItemDetail() == nil then
  451.                             breedaction('pull',2,16,i)
  452.                             more = true
  453.                         end
  454.                     end
  455.                 end
  456.             end
  457.             if more == false then
  458.                 print("couldn't find enough chickens")
  459.                 error()
  460.             else
  461.                 start()
  462.             end
  463.         end
  464.     end
  465.     turtle.select(oslot1)
  466.     turtle.transferTo(chicken1)
  467.     turtle.select(oslot2)
  468.     turtle.transferTo(chicken2)
  469.     turtle.select(oslot1)
  470.     turtle.transferTo(chicken1)
  471.     if trashboxthere ~= true or seedboxthere ~= true or breedboxthere ~= true then
  472.         if trashboxthere ~= true then
  473.             print("Trashbox is missing")
  474.         end
  475.         if seedboxthere ~= true then
  476.             print("Seedbox is missing")
  477.         end
  478.         if breedboxthere ~= true then
  479.             print("Breedbox is missing")
  480.         end
  481.         error()
  482.     end
  483.     breedaction("push",chicken1,16,1)
  484.     breedaction("push",chicken2,16,2)
  485.     getseeds()
  486.     fillseeds()
  487.     program()
  488. end
  489.  
  490. start()
Advertisement
Add Comment
Please, Sign In to add comment