Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- hiveNBT = peripheral.find("blockReader")
- detector = peripheral.find("environmentDetector")
- integrator = peripheral.find("redstoneIntegrator")
- beeChest = peripheral.wrap("right")
- monitor = peripheral.wrap("monitor_5")
- --integrator.getAnalogInput("top")
- local beesGenes = {
- {
- Name = "Endurance",
- Attribute = "bee_endurance",
- Values = {
- {
- Name = "Weak",
- Color = colors.green,
- BeesCount = 0
- },
- {
- Name = "Normal",
- Color = colors.blue,
- BeesCount = 0
- },
- {
- Name = "Medium",
- Color = colors.purple,
- BeesCount = 0
- },
- {
- Name = "Strong",
- Color = colors.red,
- BeesCount = 0
- },
- }
- },
- {
- Name = "Behavior",
- Attribute = "bee_behavior",
- Values = {
- {
- Name = "Diurnal",
- Color = colors.green,
- BeesCount = 0
- },
- {
- Name = "Nocturnal",
- Color = colors.blue,
- BeesCount = 0
- },
- {
- Name = "Metaturnal",
- Color = colors.purple,
- BeesCount = 0
- },
- }
- },
- {
- Name = "Weather Tolerance",
- Attribute = "bee_weather_tolerance",
- Values = {
- {
- Name = "None",
- Color = colors.green,
- BeesCount = 0
- },
- {
- Name = "Rain",
- Color = colors.blue,
- BeesCount = 0
- },
- {
- Name = "Any",
- Color = colors.purple,
- BeesCount = 0
- },
- }
- },
- {
- Name = "Temper",
- Attribute = "bee_temper",
- Values = {
- {
- Name = "Passive",
- Color = colors.green,
- BeesCount = 0
- },
- {
- Name = "Normal",
- Color = colors.blue,
- BeesCount = 0
- },
- {
- Name = "Aggressive",
- Color = colors.purple,
- BeesCount = 0
- },
- {
- Name = "Hostile",
- Color = colors.red,
- BeesCount = 0
- },
- }
- },
- {
- Name = "Productivity",
- Attribute = "bee_productivity",
- Values = {
- {
- Name = "Normal",
- Color = colors.green,
- BeesCount = 0
- },
- {
- Name = "Medium",
- Color = colors.blue,
- BeesCount = 0
- },
- {
- Name = "High",
- Color = colors.purple,
- BeesCount = 0
- },
- {
- Name = "Very High",
- Color = colors.red,
- BeesCount = 0
- },
- }
- },
- };
- local bees = {
- InHive = {
- Child = {},
- Adult = {}
- },
- OutsideHive = {
- Child = {},
- Adult = {}
- }
- };
- --Niotic Crystal Bee
- --
- --┌Bees in Hive
- --├adult => 2
- --└child => 2 Growing: 19m|5m|3m|7m|1m
- --┌Bees outside
- --└adult => 1
- --
- --┌Genes
- --├Productivity => 1 High, 2 Very high
- --├WeatherTolerance => 5 None
- --├Behavior => 5 Metaturnal
- --├Endurance => 3 Medium, 2 Strong
- --└Temper => 5 Passive
- -- hive.BeeList.Inhabitants[n]
- -- |-FlowerPos : table
- -- |-MinOccupationTick: num
- -- |-Name: string --need
- -- |-EntityData: table --need
- -- |-bee_endurance: num
- -- |-bee_behavior: num
- -- |-bee_weather_tolerance: num
- -- |-bee_temper: num
- -- |-bee_productivity: num
- -- |-age: num
- -- |-TicksInHive: num
- -- detector.scanEntities(3)[n]
- -- |-uuid: uuid
- -- |-tags: table
- -- |-id: num
- -- |-y: num
- -- |-x: num
- -- |-name: string --need
- -- |-z: num
- -- |-baby: bool --need
- -- |-inLove: bool
- -- |-aggressive: bool
- function updateBees()
- local hiveData = hiveNBT.getBlockData();
- local beesFreedom = detector.scanEntities(3);
- bees = {
- InHive = {
- Child = {},
- Adult = {}
- },
- OutsideHive = {
- Child = {},
- Adult = {}
- }
- };
- if (hiveData.BeeList ~= nil) then
- for _, bee in ipairs(hiveData.BeeList.Inhabitants) do
- print(bee.Name)
- if (bee.EntityData.Age ~= 0) then
- table.insert(bees.InHive.Child, {
- Name = bee.Name,
- });
- else
- table.insert(bees.InHive.Adult, {
- Name = bee.Name,
- });
- end
- end
- end
- if (beesFreedom ~= nil) then
- for _, entity in pairs(beesFreedom) do
- if (entity.name:find("Bee") ~= nil) then
- if (entity.baby) then
- table.insert(bees.OutsideHive.Child, { Name = entity.Name });
- else
- table.insert(bees.OutsideHive.Adult, { Name = entity.Name });
- end
- end
- end
- end
- if (#bees.InHive.Adult + #bees.InHive.Child > 0 and #bees.OutsideHive.Child + #bees.OutsideHive.Adult == 0) then
- updateGenes(hiveData)
- end
- end
- function updateGenes(hiveData)
- for i, gene in pairs(beesGenes) do
- for _, bee in ipairs(hiveData.BeeList.Inhabitants) do
- for attribute, value in pairs(bee.EntityData) do
- if (gene.Attribute == attribute) then
- gene.Values[value + 1].BeesCount = gene.Values[value + 1].BeesCount + 1;
- end
- end
- end
- end
- end
- function getBeeName()
- if (#bees.InHive.Adult + #bees.InHive.Child > 0) then
- if (#bees.InHive.Adult > 0) then
- return bees.InHive.Adult[1].Name;
- else
- return bees.InHive.Child[1].Name;
- end
- elseif (#bees.OutsideHive.Adult + #bees.OutsideHive.Child > 0) then
- if (#bees.OutsideHive.Adult > 0) then
- return bees.OutsideHive.Adult[1].Name;
- else
- return bees.OutsideHive.Child[1].Name;
- end
- end
- end
- function drawApiaryData()
- local currentXPos = 1;
- local currentYPos = 1;
- local monitorWidth, monitorHeight = monitor.getSize();
- local beeName = getBeeName();
- monitor.clear()
- monitor.setCursorPos(monitorWidth / 2 - beeName:len() / 2, currentYPos);
- monitor.write(beeName);
- currentYPos = currentYPos + 2
- monitor.setCursorPos(currentXPos, currentYPos);
- for k, v in pairs(bees) do
- if (k == "InHive") then
- if (#v.Adult > 0 or #v.Child > 0) then
- monitor.write("Bees in hive");
- currentYPos = currentYPos + 1;
- if (#v.Adult > 0) then
- monitor.setCursorPos(currentXPos, currentYPos)
- monitor.write("|-adult => " .. #v.Adult)
- currentYPos = currentYPos + 1;
- end
- if (#v.Child > 0) then
- monitor.setCursorPos(currentXPos, currentYPos)
- monitor.write("|-child => " .. #v.Child)
- currentYPos = currentYPos + 1;
- end
- currentYPos = currentYPos + 1
- end
- elseif (k == "OutsideHive") then
- if (#v.Adult > 0 or #v.Child > 0) then
- monitor.setCursorPos(currentXPos, currentYPos)
- monitor.write("Bees outside hive");
- currentYPos = currentYPos + 1;
- if (#v.Adult > 0) then
- monitor.setCursorPos(currentXPos, currentYPos)
- monitor.write("|-adult => " .. #v.Adult)
- currentYPos = currentYPos + 1;
- end
- if (#v.Child > 0) then
- monitor.setCursorPos(currentXPos, currentYPos)
- monitor.write("|-child => " .. #v.Child)
- currentYPos = currentYPos + 1;
- end
- end
- currentYPos = currentYPos + 1;
- end
- currentYPos = currentYPos + 1;
- end
- end
- function getBeeCount()
- local insideHive = 0
- local outsideHive = 0
- if (hiveNBT.getBlockData()["BeeList"] ~= nil) then
- insideHive = #hiveNBT.getBlockData()["BeeList"]["Inhabitants"]
- else
- insideHive = 0
- end
- local entityData = detector.scanEntities(3);
- if (entityData == nil) then
- return insideHive, outsideHive
- end
- for i = 1, #entityData, 1 do
- if (entityData[i]["name"]:find("Bee") ~= nil) then
- outsideHive = outsideHive + 1
- end
- end
- return insideHive, outsideHive
- end
- --10 ticks == 0.5 sec
- function cageExportControlSignal(beeCount)
- redstone.setAnalogOutput("left", 8)
- sleep(0.5 * beeCount)
- redstone.setAnalogOutput("left", 0)
- sleep(3)
- end
- function catchBeesControlSignal()
- redstone.setAnalogOutput("left", 9)
- end
- monitor.setTextScale(1)
- monitor.clear()
- beeCountToCath = 0
- updateBees();
- drawApiaryData()
- print(("Name: %s"):format(getBeeName()))
- print("Inside: " .. #bees.InHive.Adult + #bees.InHive.Child .. " | Adults: " .. #bees.InHive.Adult .. " Childrens: " .. #bees.InHive.Child);
- print("Outside: " .. #bees.OutsideHive.Adult + #bees.OutsideHive.Child .. " | Adults: " .. #bees.OutsideHive.Adult .. " Childrens: " .. #bees.OutsideHive.Child);
- print("Genes:")
- for i, gene in ipairs(beesGenes) do
- local geneString = "|-" .. gene.Name .. string.rep(" ", 19 - gene.Name:len()) .. "=>";
- for k,v in pairs(gene.Values) do
- if (v.BeesCount > 0) then
- geneString = geneString .. " " .. v.BeesCount .. " " .. v.Name .. " ";
- --print("Gene: " .. gene.Name .. " Value: " .. v.Name .. " Bees: " .. v.BeesCount)
- end
- end
- print(geneString);
- end
- local workingThreadTimerId = os.startTimer(2);
- --while true do
- -- monitor.setCursorPos(1, 1)
- -- monitor.write(getBeeName())
- -- monitor.setCursorPos(1, 2)
- -- monitor.write(getBeeName())
- -- monitor.setCursorPos(1, 3)
- -- print(("Bee in hive: %d, outside: %d"):format(beeHive, beeSpace))
- -- monitor.write(("Bee in hive: %d, outside: %d"):format(beeHive, beeSpace))
- -- if (beeCount >= 6) then
- -- redstone.setOutput("left", true)
- -- else
- -- redstone.setOutput("left", false)
- -- end
- --
- -- if event == "timer" and eventData[2] == workingThreadTimerId then
- -- updateBees()
- -- workingThreadTimerId = os.startTimer(2);
- -- end
- --end
- --while true do
- -- term.clear()
- -- local beeHive, beeSpace = getBeeCount()
- -- local beeCount = beeHive + beeSpace
- -- beeCountToCath = 0
- --
- -- if (integrator.getAnalogInput("back") == 14) then
- -- local flag = true
- -- print("Bee catching started..")
- -- while flag do
- -- term.clear()
- -- if beeCountToCath == 0 and #beeChest.list() == 0 then
- -- beeCountToCath = beeCount
- -- print(("Bee count to catch: %d"):format(beeCountToCath))
- -- cageExportControlSignal(beeCount)
- -- print("Cages sent..")
- -- end
- --
- -- catchBeesControlSignal()
- -- print(("Bees in chest: %d"):format(#beeChest.list()))
- -- if beeCountToCath == #beeChest.list() then
- -- print("All bees are caught!")
- -- beeCountToCath = 0
- -- flag = false
- -- end
- --
- -- sleep(1)
- -- end
- -- else
- -- monitor.setCursorPos(1, 1)
- -- monitor.write("Extracting genes of:")
- -- monitor.setCursorPos(1, 2)
- -- monitor.write((" %s"):format(getBeeName()))
- -- monitor.setCursorPos(1, 3)
- -- print(("Bee in hive: %d, outside: %d"):format(beeHive, beeSpace))
- -- monitor.write(("Bee in hive: %d, outside: %d"):format(beeHive, beeSpace))
- -- if (beeCount >= 6) then
- -- redstone.setOutput("left", true)
- -- else
- -- redstone.setOutput("left", false)
- -- end
- --
- -- sleep(2)
- -- end
- --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement