ecco7777

CC Genetic Sampler

Jul 9th, 2021 (edited)
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.00 KB | None | 0 0
  1. onlyAnalyzedBees=false
  2. genomeBuffer=2
  3. delay=5
  4.  
  5. function wrapPs(peripheralName)
  6.     periTab = {}
  7.     sideTab = {}
  8.     if peripheralName == nil then
  9.         print("Fehler")
  10.     end
  11.     local peripherals = peripheral.getNames()
  12.     local i2 = 1
  13.     for i = 1, #peripherals do
  14.         if peripheral.getType(peripherals[i]) == peripheralName then
  15.             periTab[i2] = peripheral.wrap(peripherals[i])
  16.             sideTab[i2] = peripherals[i]
  17.             i2 = i2 + 1
  18.         end
  19.     end
  20.     if periTab ~= {} then
  21.         return periTab, sideTab
  22.     else
  23.         return nil
  24.     end
  25.  
  26.     function getPSide(peripheralName)
  27.         if peripheralName == nil then
  28.             print("Fehler")
  29.         end
  30.         local peripherals = peripheral.getNames()
  31.         local i = 1
  32.         while i < #peripherals and peripheral.getType(peripherals[i]) ~= peripheralName do
  33.             i = i + 1
  34.         end
  35.         if peripheral.getType(peripherals[i]) == peripheralName then
  36.             return peripherals[i]
  37.         else
  38.             return nil
  39.         end
  40.     end
  41. end
  42.  
  43. me = wrapPs("appliedenergistics2:interface")[1]
  44. smplr = wrapPs("gendustry:sampler")[1]
  45. attrIndex = {"Species","Effect","Speed","Flowering","Flowers"}
  46.  
  47. function getBeeData()
  48.     bee=nil
  49.     if (smplr.getItem(3)~=nil) then
  50.         bee=smplr.getItem(3).getMetadata()
  51.     end
  52.     if bee~=nil then
  53.     beeData={}
  54.     beeData.active={}
  55.     beeData.inactive={}
  56.     beeData.active["Species"]=bee.individual.genome.active.species.displayName
  57.     beeData.inactive["Species"]=bee.individual.genome.inactive.species.displayName
  58.     end
  59.     return beeData
  60. end
  61.  
  62. function getSample(sample)
  63.     smpl={}
  64.     smpl.name=sample.getMetadata().displayName
  65.     smpl.trade=string.sub(smpl.name,14,string.find(smpl.name,":")-1)
  66.     smpl.val=string.sub(smpl.name,string.find(smpl.name,":")+2)
  67.     return smpl
  68. end
  69.    
  70. function getSamples()
  71.     smpls=me.findItems("gendustry:gene_sample")
  72.     smplsData={}
  73.     for i=1,#smpls do
  74.         table.insert(smplsData,getSample(smpls[i]))
  75.     end
  76.     return smplsData
  77. end
  78.  
  79. function beeFinished()
  80.     beeIsFinished=false
  81.     smplsData=getSamples()
  82.     beeData=getBeeData()
  83.     if beeData ~=nil then
  84.         for i=1,#smplsData do
  85.             if smplsData[i].trade=="Species" then
  86.                 if beeData.active.Species==smplsData[i].val then
  87.                     beeIsFinished=true
  88.                 end
  89.                 if beeData.inactive.Species==smplsData[i].val then
  90.                     beeIsFinished=true
  91.                 end
  92.             end
  93.         end
  94.     end
  95.     return beeIsFinished
  96. end
  97.  
  98. function dumpOverdueSamples()
  99.     smpls=me.findItems("gendustry:gene_sample")
  100.     for i=1,#smpls do
  101.         if smpls[i].getMetadata().count>genomeBuffer then
  102.             smpls[i].export("up",1)
  103.         end
  104.     end
  105. end
  106.  
  107. function main()
  108.     while true do
  109.     dumpOverdueSamples()
  110.         if beeFinished() then
  111.             smplr.pushItems("up",3)
  112.         end
  113.     end
  114.     sleep(delay)
  115. end
  116.  
  117. main()
Add Comment
Please, Sign In to add comment