Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = ""
- local rune = nil
- for k, v in pairs(peripheral.getNames()) do
- if peripheral.getType(v) == "modem" then
- modem = v
- end
- if peripheral.getType(v) == "tt_aspectContainer" then
- rune = peripheral.wrap(v)
- end
- end
- if modem ~= "" then
- rednet.open(modem)
- else
- write("need modem")
- shell.exit()
- end
- -- computer is host. turtle is bit
- if turtle then
- -------------------------------------------
- -------------- bit mode ------------------
- -------------------------------------------
- if turtle.inspect() and ({turtle.inspect()})[2].name == "Thaumcraft:blockStoneDevice" then
- else
- write("need front *arcane pedestal*")
- shell.exit()
- end
- local pedestal = peripheral.wrap("front")
- write("auto infusion bit mode")
- while true do
- local id,mes = rednet.receive()
- local datas = textutils.unserialize(mes)
- if datas and datas.channel and datas.channel == "AI" and datas.mes == "call bits" then
- if turtle.suck() then
- rednet.send(id, textutils.serialize({channel="AI",mes="leady"}))
- while true do
- id,mes = rednet.receive()
- datas = textutils.unserialize(mes)
- if datas and datas.channel and datas.channel == "AI" and datas.mes == "do it" then
- turtle.drop()
- while true do
- if #(pedestal.getAllStacks()) == 0 then
- rednet.send(id, textutils.serialize({channel="AI",mes="end"}))
- break
- end
- sleep(0.5)
- end
- break
- end
- if datas and datas.channel and datas.channel == "AI" and datas.mes == "reset" then
- turtle.drop()
- break
- end
- end
- end
- end
- end
- else
- -------------------------------------------
- -------------- host mode ------------------
- -------------------------------------------
- if not rune then
- write("need near infusion rune")
- shell.exit()
- end
- while true do
- while true do
- if #(rune.getAspects()) > 0 then
- write("\nstart infusion")
- rednet.broadcast(textutils.serialize({channel="AI",mes="call bits"}))
- break
- end
- sleep(0.5)
- end
- local tID = os.startTimer(0.5)
- local bits = {}
- local phase = 0
- while true do
- local eve = {os.pullEvent()}
- if eve[1] == "timer" and tID == eve[2] then
- local aspectEndFlg = true
- local asptext = ""
- for k, v in pairs(rune.getAspects()) do
- if rune.getAspectCount(v) > 0 then
- asptext = asptext .. v ..":" .. rune.getAspectCount(v) .. " "
- aspectEndFlg = false
- end
- end
- if aspectEndFlg and phase == 0 then
- phase = phase + 1
- rednet.send(bits[phase], textutils.serialize({channel="AI",mes="do it"}))
- end
- if #(rune.getAspects()) == 0 then
- rednet.broadcast(textutils.serialize({channel="g_inf",sender=os.getComputerID(),line={{t="auto Infusion complete",c=colors.magenta}}}))
- break
- end
- rednet.broadcast(textutils.serialize( {channel="g_inf"
- ,sender=os.getComputerID()
- ,line = {{t="auto Infusion phase:"..phase,c=colors.magenta}
- ,{t=asptext,c=colors.magenta}}}))
- tID = os.startTimer(0.5)
- end
- if eve[1] == "rednet_message" then
- local datas = textutils.unserialize(eve[3])
- if datas and datas.channel and datas.channel == "AI" and datas.mes == "leady" then
- bits[#bits+1] = eve[2]
- end
- if datas and datas.channel and datas.channel == "AI" and datas.mes == "end" then
- phase = phase + 1
- if phase <= #bits then
- write(".")
- rednet.send(bits[phase], textutils.serialize({channel="AI",mes="do it"}))
- end
- end
- end
- end
- write("complte")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement