Advertisement
ilgazzi

JarThingie

Jul 22nd, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. perilist=peripheral.getNames()
  2. ap="south"
  3. t="north"
  4. jars={}
  5. aspects={}
  6. slots={}
  7. interfaces={}
  8. analyzers={}
  9. a=nil
  10. local function perisort()
  11.     for i = 1, #perilist do
  12.         if string.find(peripheral.getType(perilist[i]),"tt_aspectContainer") and #peripheral.call(perilist[i], "getAspects")~=0 then
  13.             jars[#jars+1]=perilist[i]
  14.         elseif string.find(peripheral.getType(perilist[i]),"tileinterface") then
  15.             interfaces[#interfaces+1]=perilist[i]
  16.         elseif string.find(peripheral.getType(perilist[i]),"tt_aspectanalyzer") then
  17.             analyzers[#analyzers+1]=perilist[i]
  18.             print(analyzers[#analyzers]," connected")
  19.         end
  20.     end
  21. end
  22. local function scan()
  23.     for i = 1, #jars do
  24.         aspects[peripheral.call(jars[i], "getAspects")[1]]=peripheral.call(jars[i], "getAspectCount",peripheral.call(jars[i], "getAspects")[1])
  25.     end
  26. end
  27. local function sort()
  28.     for i=1,#interfaces do
  29.         peripheral.call(interfaces[i],"pushItem",ap,1,1)
  30.         for k=1,#analyzers do
  31.             if peripheral.call(analyzers[k], "hasItem") then
  32.                 a=peripheral.wrap(analyzers[k])
  33.             end
  34.         end
  35.         peripheral.call(interfaces[i],"pullItem",ap,1,64,1)
  36.         for j=1,8 do
  37.             if peripheral.call(interfaces[i],"getStackInSlot",j)~=nil then
  38.                 s=1
  39.                 peripheral.call(interfaces[i],"pushItem",ap,j,1)
  40.                 if a.getAspects()[1]=="auram" then
  41.                     s=2
  42.                 end
  43.                 slots[a.getAspects()[s]]={i,j}
  44.                 print(a.getAspects()[s])
  45.                 peripheral.call(interfaces[i],"pullItem",ap,1,64,j)
  46.             end
  47.         end
  48.     end
  49. end
  50. local function push(place,slot,amount)
  51.     amount=amount-(amount%2)
  52.     give=amount/2
  53.     print(interfaces[place])
  54.     peripheral.call(interfaces[place],"pushItem",t,slot,give)
  55. end
  56. perisort()
  57. sort()
  58. scan()
  59. for aspect, amount in pairs(aspects) do
  60.     print(slots[aspect][1]," ",amount)
  61.     if amount<63 then
  62.         push(slots[aspect][1],slots[aspect][2], 64-amount)
  63.         sleep(1)--((64-amount)*3)+2)
  64.     end
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement