Advertisement
Ganeesya

auto infusion アイテム待避

May 4th, 2015
13,653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.58 KB | None | 0 0
  1. local modem = ""
  2. local rune = nil
  3. for k, v in pairs(peripheral.getNames()) do
  4.     if peripheral.getType(v) == "modem" then
  5.         modem = v
  6.     end
  7.     if peripheral.getType(v) == "tt_aspectContainer" then
  8.         rune = peripheral.wrap(v)
  9.     end
  10. end
  11.  
  12. if modem ~= "" then
  13.     rednet.open(modem)
  14. else
  15.     write("need modem")
  16.     shell.exit()
  17. end
  18.  
  19. -- computer is host. turtle is bit
  20. if turtle then
  21.     -------------------------------------------
  22.     -------------- bit  mode ------------------
  23.     -------------------------------------------
  24.     if turtle.inspect() and ({turtle.inspect()})[2].name == "Thaumcraft:blockStoneDevice" then
  25.     else
  26.         write("need front *arcane pedestal*")
  27.         shell.exit()
  28.     end
  29.  
  30.     local pedestal = peripheral.wrap("front")
  31.     write("auto infusion bit mode")
  32.     while true do
  33.         local id,mes = rednet.receive()
  34.         local datas = textutils.unserialize(mes)
  35.         if datas and datas.channel and datas.channel == "AI" and datas.mes == "call bits" then
  36.             if turtle.suck() then
  37.                 rednet.send(id, textutils.serialize({channel="AI",mes="leady"}))
  38.                 while true do
  39.                     id,mes = rednet.receive()
  40.                     datas = textutils.unserialize(mes)
  41.                     if datas and datas.channel and datas.channel == "AI" and datas.mes == "do it" then
  42.                         turtle.drop()
  43.                         while true do
  44.                             if #(pedestal.getAllStacks()) == 0 then
  45.                                 rednet.send(id, textutils.serialize({channel="AI",mes="end"}))
  46.                                 break
  47.                             end
  48.                             sleep(0.5)
  49.                         end
  50.                         break
  51.                     end
  52.                     if datas and datas.channel and datas.channel == "AI" and datas.mes == "reset" then
  53.                         turtle.drop()
  54.                         break
  55.                     end
  56.                 end
  57.             end
  58.         end
  59.     end
  60. else
  61.     -------------------------------------------
  62.     -------------- host mode ------------------
  63.     -------------------------------------------
  64.     if not rune then
  65.         write("need near infusion rune")
  66.         shell.exit()
  67.     end
  68.  
  69.     while true do
  70.         while true do
  71.             if #(rune.getAspects()) > 0 then
  72.                 write("\nstart infusion")
  73.                 rednet.broadcast(textutils.serialize({channel="AI",mes="call bits"}))
  74.                 break
  75.             end
  76.             sleep(0.5)
  77.         end
  78.  
  79.         local tID = os.startTimer(0.5)
  80.         local bits = {}
  81.         local phase = 0
  82.  
  83.         while true do
  84.             local eve = {os.pullEvent()}
  85.  
  86.             if eve[1] == "timer" and tID == eve[2] then
  87.                 local aspectEndFlg = true
  88.                 local asptext = ""
  89.                 for k, v in pairs(rune.getAspects()) do
  90.                     if rune.getAspectCount(v) > 0 then
  91.                         asptext = asptext .. v ..":" .. rune.getAspectCount(v) .. " "
  92.                         aspectEndFlg = false
  93.                     end                
  94.                 end
  95.                 if aspectEndFlg and phase == 0 then
  96.                     phase = phase + 1
  97.                     rednet.send(bits[phase], textutils.serialize({channel="AI",mes="do it"}))
  98.                 end
  99.                 if #(rune.getAspects()) == 0 then
  100.                     rednet.broadcast(textutils.serialize({channel="g_inf",sender=os.getComputerID(),line={{t="auto Infusion complete",c=colors.magenta}}}))
  101.                     break
  102.                 end
  103.  
  104.                 rednet.broadcast(textutils.serialize(   {channel="g_inf"
  105.                                                         ,sender=os.getComputerID()
  106.                                                         ,line = {{t="auto Infusion phase:"..phase,c=colors.magenta}
  107.                                                                 ,{t=asptext,c=colors.magenta}}}))
  108.                 tID = os.startTimer(0.5)
  109.             end
  110.  
  111.             if eve[1] == "rednet_message" then
  112.                 local datas = textutils.unserialize(eve[3])
  113.                 if datas and datas.channel and datas.channel == "AI" and datas.mes == "leady" then
  114.                     bits[#bits+1] = eve[2]
  115.                 end
  116.                 if datas and datas.channel and datas.channel == "AI" and datas.mes == "end" then
  117.                     phase = phase + 1
  118.                     if phase <= #bits then
  119.                         write(".")
  120.                         rednet.send(bits[phase], textutils.serialize({channel="AI",mes="do it"}))
  121.                     end
  122.                 end
  123.             end
  124.         end
  125.         write("complte")
  126.     end
  127. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement