william200027

MakeAtom

May 10th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.08 KB | None | 0 0
  1. -- @title makeAtom
  2. -- @description A Chemistry Turtle programm to process every atom you want with a Fusion Chamber, Oxygene and Hydrogene
  3. -- @author Flaming Talisker
  4. -- @authorYT http://youtube.com/FlamingTalisker (funny french inside)
  5. -- @version pre alpha anticiped release (because fuck customers)
  6. -- @remarque most commentary are in french, because i'am and i pee on other langage to show dominance
  7. -- @licence nudeware, send me a nude of you to commercialy use this
  8. -- @excuse sorry, it was a joke
  9. -- @... stop with @, go home, you're drunk
  10.  
  11.  
  12. -- adapt this setting to your world and needs
  13. local atom_target = 79                  -- atom number to be created
  14. local stack_size = 64                   -- size of stack to be created ! (you don't say !)
  15. local direction_left = "north"          -- because side and direction blow our mind
  16. local direction_right ="south"          -- indeed *Teal'c voice*
  17. local pause = 5                         -- sleep time in sec between 2 checks, you don't want to smash your server, don't you ?
  18. if pause == 0 then pause = 1 end        -- are you a lama ?
  19.  
  20. -- don't touch that bitch
  21. local fusion = peripheral.wrap("right") -- la fusion chamber
  22. local chest = peripheral.wrap("top")    -- le chest des atomes finaux
  23. local chest1 = peripheral.wrap("front") -- chest de gauche
  24. local chest2 = peripheral.wrap("back")  -- chest de droite
  25. local mchem = peripheral.wrap("left")   -- Minechem Atomic manipulator
  26.  
  27.  
  28. -- process principal
  29. function main()
  30.  
  31.   -- boucle infinie
  32.   while true do
  33.  
  34.     -- activation pause
  35.     make_pause = true
  36.  
  37.     -- verifions ce qu'il y a dans la fusion chamber
  38.     stack1 = fusion.getStackInSlot(1)
  39.     stack2 = fusion.getStackInSlot(2)
  40.  
  41.     if stack1 == nil and stack2 == nil then
  42.       -- la chamber fusion est prete a un nouveau process, decidons quoi faire...  
  43.  
  44.       turtle_slot = checkProcessInChest()
  45.  
  46.       -- si aucun element n'est a process dans la turtle
  47.       if turtle_slot == 0 then
  48.  
  49.         -- si atom cible inferieur ou egal a O
  50.         if atom_target <= 8 then
  51.           -- on envoi 2 H
  52.           chest1.pullItem("down",2,stack_size)
  53.           chest2.pullItem("down",2,stack_size)
  54.         -- si atome entre 8 et 15
  55.         else
  56.           if atom_target < 16 then
  57.             -- on envoi 1 O et 1H
  58.             chest1.pullItem("up",2,stack_size)
  59.             chest2.pullItem("down",2,stack_size)
  60.           -- si atome superieur ou egal a 2 O
  61.           else
  62.             -- on envoi 2 oxygene
  63.             chest1.pullItem("up",2,stack_size)
  64.             chest2.pullItem("up",2,stack_size)
  65.           end
  66.         end
  67.  
  68.       -- sinon on s'en occupe
  69.       else
  70.  
  71.         -- si c'est l'atom cible
  72.         if mchem.getAtomicMass() == atom_target then
  73.           -- on le met dans le chest final
  74.           chest.pullItem("down",turtle_slot,stack_size)
  75.           -- on desactive la pause parce que pas besoin du coup
  76.           make_pause = false
  77.           -- on ecrit une connerie pour dire qu'on est content
  78.           print("One stack of "..stack_size.." element(s) "..atom_target.." created !")
  79.  
  80.         -- sinon si l'ecart de l'atom cible est superieur a O
  81.         else
  82.           if atom_target - mchem.getAtomicMass() >= 8 then
  83.             -- on l'envoi a gauche et oxygene a droite
  84.             chest1.pullItem(direction_right,turtle_slot,stack_size)
  85.             chest2.pullItem("up",2,stack_size)
  86.  
  87.           -- sinon l'ecart de l'atom cible est inferieur a O
  88.           else
  89.             -- on l'envoi a gauche et hydrogene a droite
  90.             chest1.pullItem(direction_right,turtle_slot,stack_size)
  91.             chest2.pullItem("down",2,stack_size)
  92.           end      
  93.         end
  94.       end
  95.  
  96.       -- on fait une pause pour attendre que les elements arrivent dans le fusion
  97.       -- parce que les pipes ca rame sa race grave
  98.       if make_pause then sleep(pause) end
  99.  
  100.  
  101.     else
  102.       -- la fusion chamber travaille, on a rien a faire
  103.       -- une attente active etant degeulasse par nature on reduit sa nuisance en faisant une pause
  104.       -- sinon Azenet va me defoncer
  105.       print("pause "..pause.." sec")
  106.       sleep(pause)
  107.  
  108.     end
  109.  
  110.   end
  111.  
  112. end
  113.  
  114.  
  115. -- fonction qui scan la turtle pour voir si on a des atome a process
  116. function checkProcessInChest()
  117.  
  118.   -- on parcour tous les slots de la turtle
  119.     for i=1,16 do
  120.  
  121.       turtle.select(i)
  122.  
  123.       -- si nous avons quelque chose dans le slot dans la bonne quantite
  124.       if turtle.getItemCount() >= stack_size then
  125.        
  126.         -- si c'est un element chimique
  127.         if mchem.getAtomicMass() > 0 then
  128.            
  129.           -- on retourne le slot a processer
  130.           return i
  131.  
  132.         end
  133.       end
  134.  
  135.     end
  136.  
  137.   -- on a rien trouve
  138.   return 0
  139.  
  140. end
  141.  
  142.  
  143.  
  144. main()
  145.  
  146.  
  147. -- code pour exemple
  148. function dontcallme()
  149.  
  150.   stack1 = fusion.getStackInSlot(1)
  151.  
  152.   if stack1 ~= nil and stack1.raw_name == "minechem.itemelement.o" then
  153.     print("oxygen")
  154.   end
  155.      
  156.   print("------------------")
  157.   for item,content in pairs(stack1) do
  158.     print(item)
  159.   end
  160.  
  161.   chest.pullItem("down",2,1) -- direction, slot, nb
  162.  
  163. end
Add Comment
Please, Sign In to add comment