Hiranus

Ballad of Alchemy Automation

Jul 12th, 2015
1,129
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.81 KB | None | 0 0
  1. --------Ingredients Section
  2. local alchemy = {}
  3. function AlchemicalCrafting (item,name,ing)
  4.     local tab = {}
  5.     tab.item = item
  6.     tab.name = name
  7.     tab.ingredients = ing
  8.     return tab
  9. end
  10. function Item (name,damage)
  11.     local tab = {}
  12.     tab.id = name
  13.     tab.dmg = damage
  14.     return tab
  15. end
  16. alchemy[1] = AlchemicalCrafting(Item("AWWayofTime:simpleCatalyst",0),"Simple Catalyst",
  17. {
  18.     alchemical = {
  19.     Item("minecraft:gunpowder",0),
  20.     },
  21.     other = {
  22.         Item("minecraft:sugar",0),
  23.         Item("minecraft:redstone",0),
  24.         Item("minecraft:redstone",0),
  25.         Item("minecraft:glowstone_dust",0),
  26.        
  27.     }
  28. })
  29. alchemy[2] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",3),"Strengthened Catalyst",
  30. {
  31.     alchemical = {
  32.         Item("AWWayofTime:simpleCatalyst",0),
  33.         Item("AWWayofTime:simpleCatalyst",0)
  34.     },
  35.     other = {
  36.         Item("minecraft:nether_wart",0),
  37.         Item("minecraft:dye",15)
  38.     }
  39. })
  40. alchemy[3] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",4),"Concentrated Catalyst",
  41. {
  42.     alchemical = {
  43.         Item("AWWayofTime:bloodMagicBaseAlchemyItems",3),
  44.         Item("AWWayofTime:bloodMagicBaseAlchemyItems",5)
  45.     },
  46.     other = {
  47.         Item("minecraft:gold_nugget")
  48.     }
  49. })
  50. alchemy[4] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",5),"Fractured Bone",
  51. {
  52.     alchemical = {
  53.     Item("minecraft:gunpowder",0),
  54.     },
  55.     other = {
  56.         Item("minecraft:bone",0),
  57.         Item("minecraft:bone",0),
  58.         Item("minecraft:bone",0),
  59.         Item("minecraft:bone",0),
  60.        
  61.     }
  62. })
  63. alchemy[5] = AlchemicalCrafting(Item("AWWayofTime:incendium",0),"Incendium",
  64. {
  65.     alchemical = {
  66.         Item("AWWayofTime:simpleCatalyst",0)
  67.     },
  68.     other = {
  69.         Item("minecraft:lava_bucket",0),
  70.         Item("minecraft:blaze_powder",0),
  71.         Item("minecraft:blaze_powder",0),
  72.         Item("minecraft:netherrack",0)
  73.     }
  74. })
  75. alchemy[6] = AlchemicalCrafting(Item("AWWayofTime:aether",0),"Aether",
  76. {
  77.     alchemical = {
  78.         Item("AWWayofTime:simpleCatalyst",0)
  79.     },
  80.     other = {
  81.         Item("minecraft:ghast_tear",0),
  82.         Item("minecraft:feather",0),
  83.         Item("minecraft:feather",0),
  84.         Item("minecraft:glowstone_dust",0)
  85.     }
  86. })
  87. alchemy[7] = AlchemicalCrafting(Item("AWWayofTime:sanctus",0),"Sanctus",
  88. {
  89.     alchemical = {
  90.         Item("AWWayofTime:simpleCatalyst",0)
  91.     },
  92.     other = {
  93.         Item("minecraft:gold_nugget",0),
  94.         Item("minecraft:glass",0),
  95.         Item("minecraft:glowstone_dust",0),
  96.         Item("minecraft:glowstone_dust",0)
  97.     }
  98. })
  99. alchemy[8] = AlchemicalCrafting(Item("AWWayofTime:crepitous",0),"Crepitous",
  100. {
  101.     alchemical = {
  102.         Item("AWWayofTime:simpleCatalyst",0),
  103.         Item("minecraft:gunpowder",0),
  104.         Item("minecraft:gunpowder",0),
  105.     },
  106.     other = {
  107.         Item("minecraft:cobblestone",0),
  108.         Item("minecraft:cobblestone",0)
  109.     }
  110. })
  111. alchemy[9] = AlchemicalCrafting(Item("AWWayofTime:crystallos",0),"Crystallos",
  112. {
  113.     alchemical = {
  114.         Item("AWWayofTime:simpleCatalyst",0)
  115.     },
  116.     other = {
  117.         Item("minecraft:ice",0),
  118.         Item("minecraft:ice",0),
  119.         Item("minecraft:snow",0),
  120.         Item("minecraft:snow",0)
  121.     }
  122. })
  123. alchemy[10] = AlchemicalCrafting(Item("AWWayofTime:terrae",0),"Terrae",
  124. {
  125.     alchemical = {
  126.         Item("AWWayofTime:simpleCatalyst",0)
  127.     },
  128.     other = {
  129.         Item("minecraft:sand",0),
  130.         Item("minecraft:dirt",0),
  131.         Item("minecraft:obsidian",0),
  132.         Item("minecraft:obsidian",0)
  133.     }
  134. })
  135. alchemy[11] = AlchemicalCrafting(Item("AWWayofTime:aquasalus",0),"Aquasalus",
  136. {
  137.     alchemical = {
  138.         Item("AWWayofTime:simpleCatalyst",0),
  139.     },
  140.     other = {
  141.         Item("minecraft:dye",0),
  142.         Item("minecraft:potion",0),
  143.         Item("minecraft:potion",0),
  144.         Item("minecraft:potion",0),
  145.     }
  146. })
  147. alchemy[12] = AlchemicalCrafting(Item("AWWayofTime:tennebrae",0),"Tenebrae",
  148. {
  149.     alchemical = {
  150.         Item("AWWayofTime:simpleCatalyst",0),
  151.         Item("minecraft:coal",0),
  152.         Item("minecraft:coal",0),
  153.     },
  154.     other = {
  155.         Item("minecraft:dye",0),
  156.         Item("minecraft:clay_ball",0),
  157.     }
  158. })
  159. alchemy[13] = AlchemicalCrafting(Item("AWWayofTime:magicales",0),"Magicales",
  160. {
  161.     alchemical = {
  162.         Item("AWWayofTime:simpleCatalyst",0),
  163.         Item("minecraft:gunpowder",0),
  164.     },
  165.     other = {
  166.         Item("minecraft:glowstone_dust",0),
  167.         Item("minecraft:glowstone_dust",0),
  168.         Item("minecraft:redstone",0),
  169.        
  170.     }
  171. })
  172. alchemy[14] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",0),"Offensa",
  173. {
  174.     alchemical = {
  175.         Item("AWWayofTime:bloodMagicBaseAlchemyItems",3),
  176.         Item("AWWayofTime:incendium",0),
  177.     },
  178.     other = {
  179.         Item("minecraft:arrow",0),
  180.         Item("minecraft:arrow",0),
  181.         Item("minecraft:flint",0)
  182.     }
  183. })
  184. alchemy[15] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",1),"Praesidium",
  185. {
  186.     alchemical = {
  187.         Item("AWWayofTime:bloodMagicBaseAlchemyItems",3),
  188.         Item("AWWayofTime:tennebrae",0),
  189.         Item("minecraft:web",0),
  190.     },
  191.     other = {
  192.         Item("minecraft:iron_ingot",0),
  193.         Item("minecraft:redstone",0)
  194.     }
  195. })
  196. alchemy[16] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",2),"Orbis Terrae",
  197. {
  198.     alchemical = {
  199.         Item("AWWayofTime:bloodMagicBaseAlchemyItems",3),
  200.         Item("AWWayofTime:terrae",0),
  201.         Item("minecraft:gunpowder",0),
  202.     },
  203.     other = {
  204.        
  205.         Item("minecraft:sand",0),
  206.         Item("minecraft:netherrack",0)
  207.     }
  208. })
  209. alchemy[17] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",6),"Virtus",
  210. {
  211.     alchemical = {
  212.         Item("minecraft:coal",0),
  213.         Item("AWWayofTime:bloodMagicBaseAlchemyItems",3),
  214.     },
  215.     other = {
  216.         Item("minecraft:gunpowder",0),
  217.         Item("minecraft:redstone",0),
  218.         Item("minecraft:redstone",0)
  219.     }
  220. })
  221. alchemy[18] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",7),"Reductus",
  222. {
  223.     alchemical = {
  224.         Item("AWWayofTime:bloodMagicBaseAlchemyItems",3),
  225.     },
  226.     other = {
  227.         Item("minecraft:carrot",0),
  228.         Item("minecraft:gold_ingot",0),
  229.         Item("minecraft:soul_sand",0),
  230.         Item("minecraft:redstone",0)
  231.     }
  232. })
  233. alchemy[19] = AlchemicalCrafting(Item("AWWayofTime:bloodMagicBaseAlchemyItems",8),"Potentia",
  234. {
  235.  
  236.     alchemical = {
  237.         Item("AWWayofTime:bloodMagicBaseAlchemyItems",3),
  238.     },
  239.     other = {
  240.         Item("minecraft:glowstone_dust",0),
  241.         Item("minecraft:quartz",0),
  242.         Item("minecraft:dye",4),
  243.         Item("minecraft:dye",4)
  244.     }
  245. })
  246. alchemy[20] = AlchemicalCrafting(Item("minecraft:web",0),"Cobweb",
  247. {
  248.  
  249.     alchemical = {
  250.     },
  251.     other = {
  252.         Item("minecraft:string",0),
  253.         Item("minecraft:string",0),
  254.         Item("minecraft:string",0),
  255.         Item("minecraft:string",0),
  256.         Item("minecraft:string",0)
  257.     }
  258. })
  259.  
  260. alchemy[21] = AlchemicalCrafting(Item("minecraft:gunpowder",0),"Gunpowder",
  261. {
  262.  
  263.     alchemical = {
  264.         Item("minecraft:coal",0),
  265.     },
  266.     other = {
  267.         Item("minecraft:gunpowder",0),
  268.         Item("minecraft:sand",0),
  269.  
  270.     }
  271. })
  272. alchemy[22] = AlchemicalCrafting(Item("minecraft:coal",0),"Coal",
  273. {
  274.  
  275.     alchemical = {
  276.     },
  277.     other = {
  278.         Item("minecraft:charcoal",0),
  279.         Item("minecraft:charcoal",0),
  280.         Item("minecraft:charcoal",0),
  281.         Item("minecraft:charcoal",0),
  282.         Item("minecraft:charcoal",0)
  283.     }
  284. })
  285.  
  286. ----------End of ingredients section
  287.  
  288. -----"Limits" section
  289. local quantities = {}
  290. function PrepareConfig ()
  291.    
  292.     for i=1,#alchemy do
  293.         quantities[i]={}
  294.         quantities[i].name = alchemy[i].name
  295.         quantities[i].lowPriNum = 50
  296.         quantities[i].highPriNum = 25
  297.     end
  298.     cfg=fs.open("config.cfg","w")
  299.     cfg.write(textutils.serialize(quantities))
  300.     cfg.flush()
  301.     cfg.close()
  302. end
  303. function LoadConfig()
  304.     local cfg = fs.open("config.cfg", "r")
  305.     quantities = textutils.unserialize( cfg.readAll() )  
  306.     cfg.close()
  307. end
  308. -----End of "Limits" Section
  309.  
  310. ----Peripheral section
  311. local aeInterface
  312. local chest
  313. local altar
  314. function Peripherals ()
  315.     local per_found=0
  316.     per_list = peripheral.getNames()
  317.     for i = 1, #per_list do
  318.         if peripheral.getType(per_list[i]) == "tileinterface" then
  319.             aeInterface = peripheral.wrap(per_list[i])
  320.             per_found=per_found+1
  321.             print (" Found AE Interface")
  322.         elseif  peripheral.getType(per_list[i]) == "tealtar" then
  323.             altar = peripheral.wrap(per_list[i])
  324.             per_found=per_found+1
  325.             print (" Found Altar")
  326.         else
  327.             methods = peripheral.getMethods(per_list[i])
  328.             for j = 1, #methods do
  329.                     if methods[j] == "getStackInSlot" then
  330.                             chest = peripheral.wrap(per_list[i])
  331.                             per_found=per_found+1
  332.                             print (" Found altar 'storage'")
  333.                     end
  334.             end
  335.         end
  336.     end
  337.     if per_found ~= 3 then
  338.     error("missing Peripherals") end
  339. end
  340. ----End of Peripheral section
  341.  
  342.  
  343. ----List Section
  344. local lowPriorityList = {}
  345. local highPriorityList = {}
  346. function PrepareListConnectionIDs()
  347.     for i=1, #quantities do
  348.         for j=1 ,#alchemy do
  349.             if quantities[i].name == alchemy[j].name then
  350.                 quantities[i].alchemyID = j
  351.                 alchemy[j].quantitiesID = i
  352.                 break
  353.             end
  354.         end
  355.     end
  356. end
  357. function RefreshLists ()
  358.     lowPriorityList = {}
  359.     highPriorityList = {}
  360.     for i=1, #quantities do
  361.    
  362.  
  363.         detail = aeInterface.getItemDetail(alchemy[quantities[i].alchemyID].item)
  364.  
  365.         if detail ~= nil then
  366.            
  367.             qty = detail.basic().qty
  368.             if qty<quantities[i].highPriNum then
  369.                 highPriorityList[#highPriorityList +1] = i
  370.             elseif qty<quantities[i].lowPriNum then
  371.                 lowPriorityList[#lowPriorityList +1] = i
  372.             end
  373.         else
  374.             highPriorityList[#highPriorityList +1] = i
  375.         end
  376.     end
  377. end
  378. ----End of List Section
  379.  
  380.  
  381. --crafting section
  382. local currentlyCrafted
  383.  
  384. function DetermineCrafting()
  385.     if #highPriorityList ~= 0 then
  386.         if #highPriorityList == 1 then
  387.             FindAndFillAltar(highPriorityList[1])
  388.         else
  389.             ingredient = alchemy[quantities[highPriorityList[1]].alchemyID].ingredients.alchemical
  390.             if #ingredient == 0 then
  391.                 FindAndFillAltar(highPriorityList[1])
  392.             else
  393.             local ing
  394.                 for i=1, #ingredient do
  395.            
  396.                     ing = CheckParents(ingredient[i])
  397.                     if ing ~= nil then
  398.                         break
  399.                     end
  400.                 end
  401.                    
  402.                 if ing == nil then
  403.                     FindAndFillAltar(highPriorityList[1])
  404.                 else
  405.                     FindAndFillAltar(ing)
  406.                 end
  407.                
  408.             end
  409.         end
  410.     elseif #lowPriorityList ~= 0 then
  411.         slot = FindInChest(quantities[lowPriorityList[1]].name)
  412.         if currentlyCrafted ~= lowPriorityList[1] then
  413.             if currentlyCrafted ~= nil then
  414.                 EmptyAltar()
  415.             end
  416.             FillAltar(slot,lowPriorityList[1])
  417.         end
  418.     else
  419.         if currentlyCrafted ~= nil then
  420.             EmptyAltar()
  421.         end
  422.     end
  423. end
  424.  
  425.  
  426.  
  427.  
  428. function CheckParents (item)
  429.     local toCraft = nil
  430.    
  431.     currItem = FindAlchemyIngredient(item)
  432.    
  433.    
  434.     if alchemy[currItem].quantitiesID ~=nil then
  435.         for i=1, #highPriorityList do
  436.             if alchemy[currItem].quantitiesID == highPriorityList[i] then
  437.                 toCraft = highPriorityList[i]
  438.                 break
  439.             end
  440.         end
  441.     end
  442.     local alchIng = alchemy[currItem].ingredients.alchemical
  443.     if #alchIng ~= 0 then
  444.         local deepSearch = nil
  445.         for i=1,#alchIng do
  446.             deepSearch = CheckParents(alchIng[i])
  447.             if deepSearch ~= nil then
  448.  
  449.                 toCraft = deepSearch
  450.                 break
  451.             end
  452.         end
  453.     end
  454.     return toCraft
  455. end
  456. ---End of crafting section
  457.  
  458. ---random section
  459.  
  460. function FindInChest(item_name)
  461.     maxslots = chest.getInventorySize()
  462.     for i=1, maxslots do
  463.         ch = chest.getStackInSlot(i)
  464.         if ch ~= nil then
  465.             if item_name == ch.display_name then
  466.                 return i
  467.             end
  468.         end
  469.     end
  470. end
  471. function EmptyAltar()
  472.     altar.pushItem(2,1)
  473.     currentlyCrafted = nil
  474. end
  475. function FillAltar(slot,item)
  476.     if slot ~= nil then
  477.     chest.pushItem(1,slot)
  478.     currentlyCrafted = item
  479.     else
  480.        
  481.         error("Missing item in chest: " .. quantities[item].name .. ". Terminating")
  482.     end
  483. end
  484. function FindAlchemyIngredient (item)
  485.     local alchIng
  486.    
  487.     for i=1, #alchemy do
  488.         if item.id == alchemy[i].item.id and item.dmg == alchemy[i].item.dmg then
  489.             alchIng=i
  490.         end
  491.     end
  492.     return alchIng
  493. end
  494. function FindAndFillAltar (id)
  495.     slot = FindInChest(quantities[id].name)
  496.     if currentlyCrafted ~= id then
  497.         if currentlyCrafted ~= nil then
  498.             EmptyAltar()
  499.         end
  500.         FillAltar(slot,id)
  501.     end
  502. end
  503.  
  504. ---end of random section
  505. if fs.exists("config.cfg") then
  506.     LoadConfig()
  507.     Peripherals()
  508.     altar.pushItem(2,1)
  509.     PrepareListConnectionIDs()
  510.     sleep(5)
  511.     while true do
  512.         RefreshLists()
  513.         DetermineCrafting()
  514.         sleep(8)
  515.     end
  516.    
  517. else
  518.     PrepareConfig()
  519.     print (" File 'config.cfg' was generated. Edit it to suit your needs and launch app again")
  520. end
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment