Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local serialization = require("serialization")
- local computer = component.computer
- local me = component.me_controller
- local io = require("io")
- local os = require("os")
- local db = component.proxy("da7631fe-9737-4872-921c-fa0aa5e4e76a") -- Database filter with Jars
- local interface_to_placer = component.proxy("16be86ff-5248-4ed8-bdb9-a9b98f38ed9b") -- Export Bus to Placer
- local rs = component.proxy("6a314dad-8b86-4821-ad83-82ac602fbd50") -- Redstone I/O
- local me_interface = component.proxy("ebe2e35d-443c-4aac-81de-a7293db6c228") -- me_interface to Robot
- local term = require("term")
- local thread = require("thread")
- local jar_tmp = component.proxy("bbcaff5a-d326-47b6-9652-8444805ebc5a") -- Temp Jar
- local jar_exist = component.type("bbcaff5a-d326-47b6-9652-8444805ebc5a")
- -- db size: 54
- -- side: 5 - сторона dynamist tablet'a
- -- side: 2 - сторона toggle bus'a
- -- side: 1 - сторона block placer'a
- zink = {name="zink",total=2,{element="Metallum", count=2}, {element="Sano", count=1}}
- antimony = {name="antimony",total=2,{element="Metallum", count=2}, {element="Aqua", count=1}}
- nickel = {name="nickel",total=2,{element="Metallum", count=2}, {element="Ignis", count=1}}
- cobalt = {name="cobalt",total=2,{element="Metallum", count=2}, {element="Instrumentum", count=1}}
- electrum = {name="electrum",total=2,{element="Metallum", count=2}, {element="Lucrum", count=1}}
- brass = {name="brass",total=2,{element="Metallum", count=2}, {element="Instrumentum", count=1}}
- battery_alloy = {name="battery_alloy",total=3,{element="Metallum", count=2}, {element="Aqua", count=1}, {element="Ordo", count=1}}
- soldering_alloy = {name="soldering_alloy",total=3,{element="Metallum", count=2}, {element="Aqua", count=1}, {element="Vitreus", count=1}}
- invar = {name="invar",total=2,{element="Metallum", count=2}, {element="Gelum", count=1}}
- cupronickel = {name="cupronickel",total=3,{element="Metallum", count=2}, {element="Ignis", count=1}, {element="Permutatio", count=1}}
- bismuth = {name="bismuth",total=2,{element="Metallum", count=2}, {element="Instrumentum", count=1}}
- aluminium = {name="aluminium",total=4,{element="Metallum", count=2}, {element="Ignis", count=1}, {element="Ordo", count=1}, {element="Volatus", count=1}}
- function has_value (tab, val)
- if tab[1] then
- for a,b in ipairs(tab) do
- if string.find(b.label, val) then
- return true
- end
- end
- return false
- else
- for key, value in pairs(tab) do
- if key == val then
- return true
- end
- end
- return false
- end
- end
- function tablelength(T)
- local count = 0
- for _ in pairs(T) do count = count + 1 end
- return count
- end
- -- zink == Metallum:2, Sano:1
- -- antimony == Metallum:2, Aqua:1
- -- nickel == Metallum:2, Ignis:1
- -- cobalt == Metallum:2, Instrumentum:1
- -- electrum == Metallum:2, Lucrum:1
- -- brass == Metallum:2, Instrumentum:1
- -- battery_alloy == Metallum:2, Aqua:1, Ordo:1
- -- soldering_alloy == Metallum:2, Aqua:1, Vitreus:1
- -- invar == Metallum:2, Gelum:1
- -- cupronickel == Metallum:2, Ignis:1, Permutatio:1
- -- bismuth == Metallum:2, Instrumentum:1
- -- aluminium == Metallum:2, Ignis:1, Ordo:1, Volatus:1
- print("====== Choise Ingot =======\n\n==> zink <==\n==> antimony <==\n==> nickel <==\n==> cobalt <==\n\n==> electrum <==\n==> brass <==\n==> battery_alloy <==\n==> soldering_alloy <==\n==> invar <==\n==> cupronickel <==\n==> bismuth <==\n\n==> aluminium <==")
- function ingot_info(ingot)
- if ingot[4] then
- print("Current Ingot: "..ingot.name.."\nEssentia's for create: "..ingot.total.."\nElements: "..ingot[1].element.." | "..ingot[2].element.." | "..ingot[3].element.." | "..ingot[4].element.."\n")
- elseif not ingot[4] and ingot[3] then
- print("Current Ingot: "..ingot.name.."\nEssentia's for create: "..ingot.total.."\nElements: "..ingot[1].element.." | "..ingot[2].element.." | "..ingot[3].element.."\n")
- elseif not ingot[4] and not ingot[3] then
- print("Current Ingot: "..ingot.name.."\nEssentia's for create: "..ingot.total.."\nElements: "..ingot[1].element.." | "..ingot[2].element.."\n")
- end
- end
- ingot = "aluminium"
- --ingot = io.read()
- if ingot == "zink" then
- ingot = zink
- ingot_info(ingot)
- elseif ingot == "antimony" then
- ingot = antimony
- ingot_info(ingot)
- elseif ingot == "nickel" then
- ingot = nickel
- ingot_info(ingot)
- elseif ingot == "cobalt" then
- ingot = cobalt
- ingot_info(ingot)
- elseif ingot == "electrum" then
- ingot = electrum
- ingot_info(ingot)
- elseif ingot == "brass" then
- ingot = brass
- ingot_info(ingot)
- elseif ingot == "battery_alloy" then
- ingot = battery_alloy
- ingot_info(ingot)
- elseif ingot == "soldering_alloy" then
- ingot = soldering_alloy
- ingot_info(ingot)
- elseif ingot == "invar" then
- ingot = invar
- ingot_info(ingot)
- elseif ingot == "cupronickel" then
- ingot = cupronickel
- ingot_info(ingot)
- elseif ingot == "bismuth" then
- ingot = bismuth
- ingot_info(ingot)
- elseif ingot == "aluminium" then
- ingot = aluminium
- ingot_info(ingot)
- else
- print("Error | Put value from list")
- os.exit()
- end
- os.sleep(3)
- for component = 1, ingot.total do
- print("Element: "..ingot[component].element.." | "..ingot[component].count)
- end
- essentia = me.getEssentiaInNetwork()
- essentia_count = essentia.n
- ingot_essentias = {}
- for elem = 1, ingot.total do
- table.insert(ingot_essentias, ingot[elem].element)
- end
- --TODO: Надо доделать правильный перебор эссенций ниже
- print("Проверка в реал тайме...")
- os.sleep(2)
- function jars_in_me(essence_list)
- no_jars = {}
- for k,v in pairs(essence_list) do
- for i=1, items_count do
- if not items[i] then
- elseif items[i].label == "Jar of Essentia" and items[i].aspects[1].name == k and v == false then
- name = items[i].aspects[1].name
- size = items[i].size
- no_jars[name] = size
- end
- end
- end
- return no_jars
- end
- function get_amount_essentia(filters)
- --print("checking essence")
- start_count_essentia = {}
- essentia = me.getEssentiaInNetwork()
- essentia_count = essentia.n
- for k,v in pairs(filters) do
- for i=1, essentia_count do
- if string.find(essentia[i].label, k) then
- print(k.." : "..essentia[i].amount.." | Id: "..i)
- start_count_essentia[k] = essentia[i].amount
- end
- end
- if not start_count_essentia[k] then
- print(k.." : ".." 0 ")
- start_count_essentia[k] = 0
- end
- end
- --print("checking essence end")
- return start_count_essentia
- end
- function add_filters(empty_banki)
- temp_banki = {}
- if interface_to_placer.getInterfaceConfiguration(1) ~= nil then
- for i=1,5 do interface_to_placer.setInterfaceConfiguration(i, db.address, 0) end -- Очистить фильтр
- print("Interface filters cleared")
- else end
- for k,v in pairs(empty_banki) do
- for i=1, count_banok do
- for cnt=1, 54 do
- banka_check = db.get(cnt)
- if banka_check.aspects[1].name == k then
- DB_NUMBER_JAR = cnt
- interface_to_placer.setInterfaceConfiguration(i, db.address, DB_NUMBER_JAR)
- print(db.get(cnt).aspects[1].name.." added to Export Bus")
- temp_banki[db.get(cnt).aspects[1].name] = DB_NUMBER_JAR
- end
- end
- end
- end
- return temp_banki
- end
- function place_jars()
- -- amount_essence: => {"Ordo" = 5,"Metallum" = 10}
- if not amount_essence then
- else
- --print("checking essence end")
- h = 1
- while h < 11 do
- --print("In while to 10 circle")
- if jar_exist == nil then
- --print("if jar_exist == nil then")
- rs.setOutput(1,255) rs.setOutput(1,0) -- Поставить плейсером
- print("Placed jar")
- print("Placed jar | h == "..h)
- os.sleep(1)
- jar_tmp = component.proxy("bbcaff5a-d326-47b6-9652-8444805ebc5a") -- Temp Jar
- jar_exist = component.type("bbcaff5a-d326-47b6-9652-8444805ebc5a")
- h = h + 1
- elseif component.isAvailable(jar_exist) then
- for k,v in pairs(amount_essence) do
- if jar_tmp.getAspectCount(k) == 0 then
- rs.setOutput(5,255) rs.setOutput(5,0)
- os.sleep(4)
- rs.setOutput(1,255) rs.setOutput(1,0) -- Поставить плейсером
- os.sleep(1)
- h = h + 1
- end
- end
- else
- rs.setOutput(1,255) rs.setOutput(1,0) -- Поставить плейсером
- print("Сработала ветка else и поставился плейсер")
- h = h + 1
- end
- os.sleep(0.1)
- --print("Final | h == "..h)
- h = h + 1
- end
- --print("Вышли из Final while h")
- h = 1
- end
- end
- while true do
- print("Working....")
- items = me.getItemsInNetwork()
- items_count = items.n
- essentia = me.getEssentiaInNetwork()
- essentia_count = essentia.n
- print("\n")
- check_list_essence = {}
- for component_for_ingot = 1, ingot.total do
- for ess = 1, essentia_count do
- if string.find(essentia[ess].label, ingot[component_for_ingot].element) then
- print("Now Essentia: "..ingot[component_for_ingot].element.." == "..essentia[ess].amount)
- check_list_essence[ingot[component_for_ingot].element] = true
- elseif has_value(essentia, ingot[component_for_ingot].element) == false then
- term.clear()
- print("Element: "..ingot[component_for_ingot].element.." | ".."Error | Empty")
- print("\n\nПополните банками с "..ingot[component_for_ingot].element)
- check_list_essence[ingot[component_for_ingot].element] = false
- end
- end
- end
- for component_for_ingot = 1, ingot.total do
- rez = has_value(check_list_essence, ingot[component_for_ingot].element)
- if rez == false then
- check_list_essence[ingot[component_for_ingot].element] = false
- print("Now Essentia: "..ingot[component_for_ingot].element.." | End")
- end
- end
- if check_list_essence then
- function main()
- -- DOWN NEW THREAD!
- -- empty_banki: output ===> {Metallum=150.0}
- print("empty_banki") os.sleep(0)
- empty_banki = jars_in_me(check_list_essence)
- print("count_banok")
- count_banok = tablelength(empty_banki)
- print("filters") os.sleep(0)
- filters = add_filters(empty_banki)
- if next(filters) ~= nil then
- print("amount_essence") os.sleep(0)
- amount_essence = get_amount_essentia(filters)
- print("place_jars") os.sleep(0)
- place_jars()
- end
- end
- end
- main()
- print("\n")
- os.sleep(0.1)
- term.clear()
- end
- --for item = 1, items_count do
- -- if not items[item] then
- -- else
- -- print(items[item].label.." == "..items[item].size)
- -- end
- --end
Add Comment
Please, Sign In to add comment