Advertisement
Thujed

geneExtractor

Apr 28th, 2024 (edited)
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.45 KB | None | 0 0
  1. hiveNBT = peripheral.find("blockReader")
  2. detector = peripheral.find("environmentDetector")
  3. integrator = peripheral.find("redstoneIntegrator")
  4. beeChest = peripheral.wrap("right")
  5. monitor = peripheral.wrap("monitor_5")
  6. --integrator.getAnalogInput("top")
  7.  
  8. local beesGenes = {
  9.     {
  10.         Name = "Endurance",
  11.         Attribute = "bee_endurance",
  12.         Values = {
  13.             {
  14.                 Name = "Weak",
  15.                 Color = colors.green,
  16.                 BeesCount = 0
  17.             },
  18.             {
  19.                 Name = "Normal",
  20.                 Color = colors.blue,
  21.                 BeesCount = 0
  22.             },
  23.             {
  24.                 Name = "Medium",
  25.                 Color = colors.purple,
  26.                 BeesCount = 0
  27.             },
  28.             {
  29.                 Name = "Strong",
  30.                 Color = colors.red,
  31.                 BeesCount = 0
  32.             },
  33.         }
  34.     },
  35.     {
  36.         Name = "Behavior",
  37.         Attribute = "bee_behavior",
  38.         Values = {
  39.             {
  40.                 Name = "Diurnal",
  41.                 Color = colors.green,
  42.                 BeesCount = 0
  43.             },
  44.             {
  45.                 Name = "Nocturnal",
  46.                 Color = colors.blue,
  47.                 BeesCount = 0
  48.             },
  49.             {
  50.                 Name = "Metaturnal",
  51.                 Color = colors.purple,
  52.                 BeesCount = 0
  53.             },
  54.         }
  55.     },
  56.     {
  57.         Name = "Weather Tolerance",
  58.         Attribute = "bee_weather_tolerance",
  59.         Values = {
  60.             {
  61.                 Name = "None",
  62.                 Color = colors.green,
  63.                 BeesCount = 0
  64.             },
  65.             {
  66.                 Name = "Rain",
  67.                 Color = colors.blue,
  68.                 BeesCount = 0
  69.             },
  70.             {
  71.                 Name = "Any",
  72.                 Color = colors.purple,
  73.                 BeesCount = 0
  74.             },
  75.         }
  76.     },
  77.     {
  78.         Name = "Temper",
  79.         Attribute = "bee_temper",
  80.         Values = {
  81.             {
  82.                 Name = "Passive",
  83.                 Color = colors.green,
  84.                 BeesCount = 0
  85.             },
  86.             {
  87.                 Name = "Normal",
  88.                 Color = colors.blue,
  89.                 BeesCount = 0
  90.             },
  91.             {
  92.                 Name = "Aggressive",
  93.                 Color = colors.purple,
  94.                 BeesCount = 0
  95.             },
  96.             {
  97.                 Name = "Hostile",
  98.                 Color = colors.red,
  99.                 BeesCount = 0
  100.             },
  101.         }
  102.     },
  103.     {
  104.         Name = "Productivity",
  105.         Attribute = "bee_productivity",
  106.         Values = {
  107.             {
  108.                 Name = "Normal",
  109.                 Color = colors.green,
  110.                 BeesCount = 0
  111.             },
  112.             {
  113.                 Name = "Medium",
  114.                 Color = colors.blue,
  115.                 BeesCount = 0
  116.             },
  117.             {
  118.                 Name = "High",
  119.                 Color = colors.purple,
  120.                 BeesCount = 0
  121.             },
  122.             {
  123.                 Name = "Very High",
  124.                 Color = colors.red,
  125.                 BeesCount = 0
  126.             },
  127.         }
  128.     },
  129. };
  130. local bees = {
  131.     InHive = {
  132.         Child = {},
  133.         Adult = {}
  134.     },
  135.     OutsideHive = {
  136.         Child = {},
  137.         Adult = {}
  138.     }
  139. };
  140.  
  141. --Niotic Crystal Bee
  142. --
  143. --┌Bees in Hive
  144. --├adult => 2
  145. --└child => 2 Growing: 19m|5m|3m|7m|1m
  146.  
  147. --┌Bees outside
  148. --└adult => 1
  149. --
  150. --┌Genes
  151. --├Productivity     => 1 High, 2 Very high
  152. --├WeatherTolerance => 5 None
  153. --├Behavior         => 5 Metaturnal
  154. --├Endurance        => 3 Medium, 2 Strong
  155. --└Temper           => 5 Passive
  156.  
  157.  
  158. -- hive.BeeList.Inhabitants[n]
  159. -- |-FlowerPos : table
  160. -- |-MinOccupationTick: num
  161. -- |-Name: string --need
  162. -- |-EntityData: table --need
  163. --   |-bee_endurance: num
  164. --   |-bee_behavior: num
  165. --   |-bee_weather_tolerance: num
  166. --   |-bee_temper: num
  167. --   |-bee_productivity: num
  168. --   |-age: num
  169. -- |-TicksInHive: num
  170.  
  171. -- detector.scanEntities(3)[n]
  172. -- |-uuid: uuid
  173. -- |-tags: table
  174. -- |-id: num
  175. -- |-y: num
  176. -- |-x: num
  177. -- |-name: string --need
  178. -- |-z: num
  179. -- |-baby: bool --need
  180. -- |-inLove: bool
  181. -- |-aggressive: bool
  182.  
  183. function updateBees()
  184.     local hiveData = hiveNBT.getBlockData();
  185.     local beesFreedom = detector.scanEntities(3);
  186.  
  187.     bees = {
  188.         InHive = {
  189.             Child = {},
  190.             Adult = {}
  191.         },
  192.         OutsideHive = {
  193.             Child = {},
  194.             Adult = {}
  195.         }
  196.     };
  197.  
  198.     if (hiveData.BeeList ~= nil) then
  199.         for _, bee in ipairs(hiveData.BeeList.Inhabitants) do
  200.             print(bee.Name)
  201.             if (bee.EntityData.Age ~= 0) then
  202.                 table.insert(bees.InHive.Child, {
  203.                     Name = bee.Name,
  204.                 });
  205.             else
  206.                 table.insert(bees.InHive.Adult, {
  207.                     Name = bee.Name,
  208.                 });
  209.             end
  210.         end
  211.     end
  212.  
  213.     if (beesFreedom ~= nil) then
  214.         for _, entity in pairs(beesFreedom) do
  215.             if (entity.name:find("Bee") ~= nil) then
  216.                 if (entity.baby) then
  217.                     table.insert(bees.OutsideHive.Child, { Name = entity.Name });
  218.                 else
  219.                     table.insert(bees.OutsideHive.Adult, { Name = entity.Name });
  220.                 end
  221.             end
  222.         end
  223.     end
  224.  
  225.     if (#bees.InHive.Adult + #bees.InHive.Child > 0 and #bees.OutsideHive.Child + #bees.OutsideHive.Adult == 0) then
  226.         updateGenes(hiveData)
  227.     end
  228. end
  229.  
  230. function updateGenes(hiveData)
  231.     for i, gene in pairs(beesGenes) do
  232.         for _, bee in ipairs(hiveData.BeeList.Inhabitants) do
  233.             for attribute, value in pairs(bee.EntityData) do
  234.                 if (gene.Attribute == attribute) then
  235.                     gene.Values[value + 1].BeesCount = gene.Values[value + 1].BeesCount + 1;
  236.                 end
  237.             end
  238.         end
  239.     end
  240. end
  241.  
  242. function getBeeName()
  243.     if (#bees.InHive.Adult + #bees.InHive.Child > 0) then
  244.         if (#bees.InHive.Adult > 0) then
  245.             return bees.InHive.Adult[1].Name;
  246.         else
  247.             return bees.InHive.Child[1].Name;
  248.         end
  249.     elseif (#bees.OutsideHive.Adult + #bees.OutsideHive.Child > 0) then
  250.         if (#bees.OutsideHive.Adult > 0) then
  251.             return bees.OutsideHive.Adult[1].Name;
  252.         else
  253.             return bees.OutsideHive.Child[1].Name;
  254.         end
  255.     end
  256. end
  257.  
  258. function drawApiaryData()
  259.     local currentXPos = 1;
  260.     local currentYPos = 1;
  261.     local monitorWidth, monitorHeight = monitor.getSize();
  262.     local beeName = getBeeName();
  263.  
  264.     monitor.clear()
  265.     monitor.setCursorPos(monitorWidth / 2 - beeName:len() / 2, currentYPos);
  266.     monitor.write(beeName);
  267.  
  268.     currentYPos = currentYPos + 2
  269.     monitor.setCursorPos(currentXPos, currentYPos);
  270.     for k, v in pairs(bees) do
  271.         if (k == "InHive") then
  272.             if (#v.Adult > 0 or #v.Child > 0) then
  273.                 monitor.write("Bees in hive");
  274.                 currentYPos = currentYPos + 1;
  275.                 if (#v.Adult > 0) then
  276.                     monitor.setCursorPos(currentXPos, currentYPos)
  277.                     monitor.write("|-adult => " .. #v.Adult)
  278.                     currentYPos = currentYPos + 1;
  279.                 end
  280.  
  281.                 if (#v.Child > 0) then
  282.                     monitor.setCursorPos(currentXPos, currentYPos)
  283.                     monitor.write("|-child => " .. #v.Child)
  284.                     currentYPos = currentYPos + 1;
  285.                 end
  286.  
  287.                 currentYPos = currentYPos + 1
  288.             end
  289.         elseif (k == "OutsideHive") then
  290.             if (#v.Adult > 0 or #v.Child > 0) then
  291.                 monitor.setCursorPos(currentXPos, currentYPos)
  292.                 monitor.write("Bees outside hive");
  293.                 currentYPos = currentYPos + 1;
  294.                 if (#v.Adult > 0) then
  295.                     monitor.setCursorPos(currentXPos, currentYPos)
  296.                     monitor.write("|-adult => " .. #v.Adult)
  297.                     currentYPos = currentYPos + 1;
  298.                 end
  299.  
  300.                 if (#v.Child > 0) then
  301.                     monitor.setCursorPos(currentXPos, currentYPos)
  302.                     monitor.write("|-child => " .. #v.Child)
  303.                     currentYPos = currentYPos + 1;
  304.                 end
  305.             end
  306.             currentYPos = currentYPos + 1;
  307.         end
  308.  
  309.         currentYPos = currentYPos + 1;
  310.     end
  311. end
  312.  
  313. function getBeeCount()
  314.     local insideHive = 0
  315.     local outsideHive = 0
  316.     if (hiveNBT.getBlockData()["BeeList"] ~= nil) then
  317.         insideHive = #hiveNBT.getBlockData()["BeeList"]["Inhabitants"]
  318.     else
  319.         insideHive = 0
  320.     end
  321.  
  322.     local entityData = detector.scanEntities(3);
  323.     if (entityData == nil) then
  324.         return insideHive, outsideHive
  325.     end
  326.  
  327.     for i = 1, #entityData, 1 do
  328.         if (entityData[i]["name"]:find("Bee") ~= nil) then
  329.             outsideHive = outsideHive + 1
  330.         end
  331.     end
  332.  
  333.     return insideHive, outsideHive
  334. end
  335.  
  336. --10 ticks == 0.5 sec
  337. function cageExportControlSignal(beeCount)
  338.     redstone.setAnalogOutput("left", 8)
  339.     sleep(0.5 * beeCount)
  340.     redstone.setAnalogOutput("left", 0)
  341.     sleep(3)
  342. end
  343.  
  344. function catchBeesControlSignal()
  345.     redstone.setAnalogOutput("left", 9)
  346. end
  347.  
  348. monitor.setTextScale(1)
  349. monitor.clear()
  350. beeCountToCath = 0
  351.  
  352. updateBees();
  353. drawApiaryData()
  354.  
  355. print(("Name: %s"):format(getBeeName()))
  356. print("Inside: " .. #bees.InHive.Adult + #bees.InHive.Child .. " | Adults: " .. #bees.InHive.Adult .. " Childrens: " .. #bees.InHive.Child);
  357. print("Outside: " .. #bees.OutsideHive.Adult + #bees.OutsideHive.Child .. " | Adults: " .. #bees.OutsideHive.Adult .. " Childrens: " .. #bees.OutsideHive.Child);
  358.  
  359. print("Genes:")
  360. for i, gene in ipairs(beesGenes) do
  361.     local geneString = "|-" .. gene.Name .. string.rep(" ", 19 - gene.Name:len()) .. "=>";
  362.     for k,v in pairs(gene.Values) do
  363.         if (v.BeesCount > 0) then
  364.             geneString = geneString .. " " .. v.BeesCount .. " " .. v.Name .. " ";
  365.             --print("Gene: " .. gene.Name .. " Value: " .. v.Name .. " Bees: " .. v.BeesCount)
  366.         end
  367.     end
  368.  
  369.     print(geneString);
  370. end
  371.  
  372.  
  373. local workingThreadTimerId = os.startTimer(2);
  374.  
  375. --while true do
  376. --    monitor.setCursorPos(1, 1)
  377. --    monitor.write(getBeeName())
  378. --    monitor.setCursorPos(1, 2)
  379. --    monitor.write(getBeeName())
  380. --    monitor.setCursorPos(1, 3)
  381. --    print(("Bee in hive: %d, outside: %d"):format(beeHive, beeSpace))
  382. --    monitor.write(("Bee in hive: %d, outside: %d"):format(beeHive, beeSpace))
  383. --    if (beeCount >= 6) then
  384. --        redstone.setOutput("left", true)
  385. --    else
  386. --        redstone.setOutput("left", false)
  387. --    end
  388. --
  389. --    if event == "timer" and eventData[2] == workingThreadTimerId then
  390. --        updateBees()
  391. --        workingThreadTimerId = os.startTimer(2);
  392. --    end
  393. --end
  394.  
  395. --while true do
  396. --    term.clear()
  397. --    local beeHive, beeSpace = getBeeCount()
  398. --    local beeCount = beeHive + beeSpace
  399. --    beeCountToCath = 0
  400. --
  401. --    if (integrator.getAnalogInput("back") == 14) then
  402. --        local flag = true
  403. --        print("Bee catching started..")
  404. --        while flag do
  405. --            term.clear()
  406. --            if beeCountToCath == 0 and #beeChest.list() == 0 then
  407. --                beeCountToCath = beeCount
  408. --                print(("Bee count to catch: %d"):format(beeCountToCath))
  409. --                cageExportControlSignal(beeCount)
  410. --                print("Cages sent..")
  411. --            end
  412. --
  413. --            catchBeesControlSignal()
  414. --            print(("Bees in chest: %d"):format(#beeChest.list()))
  415. --            if beeCountToCath == #beeChest.list() then
  416. --                print("All bees are caught!")
  417. --                beeCountToCath = 0
  418. --                flag = false
  419. --            end
  420. --
  421. --            sleep(1)
  422. --        end
  423. --    else
  424. --        monitor.setCursorPos(1, 1)
  425. --        monitor.write("Extracting genes of:")
  426. --        monitor.setCursorPos(1, 2)
  427. --        monitor.write(("     %s"):format(getBeeName()))
  428. --        monitor.setCursorPos(1, 3)
  429. --        print(("Bee in hive: %d, outside: %d"):format(beeHive, beeSpace))
  430. --        monitor.write(("Bee in hive: %d, outside: %d"):format(beeHive, beeSpace))
  431. --        if (beeCount >= 6) then
  432. --            redstone.setOutput("left", true)
  433. --        else
  434. --            redstone.setOutput("left", false)
  435. --        end
  436. --
  437. --        sleep(2)
  438. --    end
  439. --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement