Advertisement
AdslHouba

Automatisation des compresseurs de Galacticraft

Sep 8th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.11 KB | None | 0 0
  1. -- VIDEO SETUP : https://youtu.be/KPwwgZlGzX8
  2. -- VIDEO EXPLICATION DE CODE : https://youtu.be/LD0fan4-1uk
  3.  
  4. pp={}
  5. cote={"EAST","DOWN","WEST"}
  6. function addPP(typ,coffre,compress1,compress2,compress3,methode,qte)
  7.     pp[typ]={
  8.         coffre=peripheral.wrap(coffre),
  9.         compress={
  10.             peripheral.wrap(compress1),
  11.             peripheral.wrap(compress2),
  12.             peripheral.wrap(compress3),
  13.         },
  14.         methode=methode,
  15.         qte=qte
  16.     }
  17. end
  18. function push(coffre,cote,slotOut,qte,slotIn)
  19.     retour=0
  20.     while retour==0 do
  21.         retour=coffre.pushItemIntoSlot(cote,slotOut,qte,slotIn)
  22.     end
  23. end
  24. function pushS(coffre,cote,slotOut,qte)
  25.     retour=0
  26.     while retour==0 do
  27.         retour=coffre.pushItem(cote,slotOut,qte)
  28.     end
  29. end
  30.  
  31. complexListe={
  32.     {
  33.         {item='item.basicitem.compressedsteel',trouver=false},
  34.         {item='item.basicitem.compressedaluminum',trouver=false},
  35.         {item='item.basicitem.compressedbronze',trouver=false},
  36.         {item='item.basicitem.compressedsteel',trouver=false},
  37.         {item='item.basicitem.compressedaluminum',trouver=false},
  38.         {item='item.basicitem.compressedbronze',trouver=false}
  39.     },
  40.     {
  41.         {item='item.heavyplating',trouver=false},
  42.         {item='item.compressedmeteoriciron',trouver=false}
  43.     }
  44. }
  45. addPP("e1","copper_1","compresseur__lectrique_2","compresseur__lectrique_3","compresseur__lectrique_4","normal",2)
  46. addPP("e2","copper_2","compresseur__lectrique_6","compresseur__lectrique_7","compresseur__lectrique_5","normal",2)
  47. addPP("e3","copper_3","compresseur__lectrique_8","compresseur__lectrique_9","compresseur__lectrique_10","normal",2)
  48. addPP("e4","copper_4","compresseur__lectrique_11","compresseur__lectrique_12","compresseur__lectrique_13","normal",1)
  49. addPP("e5","copper_5","assembly_machine_3","assembly_machine_4","assembly_machine_2","simple1",2)
  50. addPP("e6","copper_6","FAUX","FAUX","FAUX","complex",2)
  51.  
  52.  
  53. while true do
  54.     table.foreach(pp,function(id,v)    
  55.         for i=1, 3 do
  56.             -- on condense les items dans le coffre de pre stockage
  57.             pp[id].coffre.condenseItems()
  58.             -- on recupΓ©re les stacks
  59.             stacks1=pp[id].coffre.getAllStacks()
  60.             -- on regarde la machine en methode normal
  61.             if pp[id].methode=="normal" then
  62.                 stacks2=pp[id].compress[i].getAllStacks()
  63.             else
  64.                 stacks2={}
  65.             end
  66.             -- Si le coffre de pre stockage contien au moin un item et que la machine est vide
  67.             if #stacks1 ~= 0 and stacks2[4]==nil and stacks2[5]==nil then              
  68.                 if pp[id].methode=="normal" then
  69.                     push(pp[id].coffre,cote[i],1,1,4)
  70.                     if pp[id].qte==2 then push(pp[id].coffre,cote[i],1,1,5) end
  71.                 elseif pp[id].methode=="simple1" then
  72.                     for u=1, pp[id].qte do
  73.                         pushS(pp[id].coffre,cote[i],1,1)                       
  74.                     end
  75.                 elseif pp[id].methode=="complex" then
  76.                     table.foreach(stacks1,function(is,data)
  77.                         trouverUneFois=false
  78.                         info=data.basic()
  79.                         for icl=1, #complexListe do
  80.                             for icl2=1, #complexListe[icl] do
  81.                                 if info.raw_name==complexListe[icl][icl2].item then
  82.                                     complexListe[icl][icl2].trouver=true
  83.                                     trouverUneFois=true
  84.                                 end
  85.                             end
  86.                         end
  87.                         if trouverUneFois==false then
  88.                             print(info.raw_name)
  89.                         end                    
  90.                     end)
  91.                     trouverUneFois=false
  92.                     for icl=1, #complexListe do        
  93.                         if trouverUneFois==false then                          
  94.                             tousOk=true
  95.                             for icl2=1, #complexListe[icl] do
  96.                                 if complexListe[icl][icl2].trouver==false then
  97.                                     tousOk=false
  98.                                 end
  99.                                 complexListe[icl][icl2].trouver=false
  100.                             end
  101.                             if tousOk then
  102.                                 trouverUneFois=true
  103.                                 retour='Envoi complexe :'
  104.                                 for icl2=1, #complexListe[icl] do
  105.                                     retour=retour..' '..complexListe[icl][icl2].item
  106.                                     trouver=false
  107.                                     table.foreach(stacks1,function(is,data)
  108.                                         if trouver==false then
  109.                                             info=data.basic()
  110.                                             if info.raw_name==complexListe[icl][icl2].item  then
  111.                                                 trouver=true
  112.                                                 push(pp[id].coffre,cote[i],is,1,3+icl2)
  113.                                             end
  114.                                         end
  115.                                     end)
  116.                                 end
  117.                                 print(retour)
  118.                             end
  119.                         else
  120.                             for icl2=1, #complexListe[icl] do
  121.                                 complexListe[icl][icl2].trouver=false
  122.                             end
  123.                         end
  124.                     end
  125.                 end            
  126.             end
  127.         end
  128.     end)
  129.     os.sleep(6)
  130. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement