OSDN Git Service

5af5155091a056030f8512eddbc2983256e6033d
[chemicraft/chemicraft.git] / common / chemicraft / system / ChemiCraftCraftingManager.java
1 package chemicraft.system;
2
3 import java.util.ArrayList;
4
5 import net.minecraft.src.IInventory;
6 import net.minecraft.src.ItemStack;
7 import chemicraft.ChemiCraftAPI;
8 import chemicraft.inventory.InventoryChemicalCraftingMaterial;
9 import chemicraft.inventory.InventoryChemicalCraftingNBT;
10 import chemicraft.inventory.InventoryChemicalCraftingResult;
11 import chemicraft.util.ChemicalNBTRecipe;
12 import chemicraft.util.FormulaPart;
13
14 public class ChemiCraftCraftingManager {
15
16         public ItemStack[] getDecompositionResults(IInventory par1IInventory){
17                 return null;
18         }
19
20
21
22         public ItemStack getChemicalCombinationResult(ArrayList<String> atomsList, ArrayList<Integer> atomsAmountList){
23                 ChemiCraftAPI api = ChemiCraftAPI.getInstance();
24                 recipeSize :
25                         for (int i = 0; i < api.getChemicalCombinationAtoms().size(); i++) {
26                                 FormulaPart[] var1 = new FormulaPart[atomsList.size()];
27                                 FormulaPart[] var2 = new FormulaPart[api.getChemicalCombinationAtoms().get(i).length];
28                                 for (int j = 0; j < atomsList.size(); j++) {
29                                         var1[j] = new FormulaPart(atomsList.get(j), atomsAmountList.get(j));
30                                 }
31                                 for (int j = 0; j < api.getChemicalCombinationAtoms().get(i).length; j++) {
32                                         var2[j] = new FormulaPart(api.getChemicalCombinationAtoms().get(i)[j], api.getChemicalCombinationAmounts().get(i)[j]);
33                                 }
34                                 if (var1.length != var2.length) {
35                                         continue recipeSize;
36                                 }
37                                 for (int j = 0; j < var1.length; j++) {
38                                         if (!var1[j].equals(var2[j])) {
39                                                 continue recipeSize;
40                                         }
41                                 }
42                                 return api.getChemicalCombinationResult().get(i);
43                         }
44                 return null;
45         }
46
47
48
49         public ChemicalNBTRecipe chemicalCrafting(InventoryChemicalCraftingMaterial par1IInventory, InventoryChemicalCraftingResult par2IInventory, InventoryChemicalCraftingNBT par3IInventory){
50                 ChemiCraftAPI api = ChemiCraftAPI.getInstance();
51                 ChemicalNBTRecipe returnObj = null;
52                 for(int i = 0;i < api.getMaterialRecipe().size();i++){
53                         ItemStack result = api.getMaterialRecipe().get(i).match(par1IInventory);
54                         ItemStack resultArg = null;
55                         if(result != null){
56                                 resultArg = new ItemStack(result.itemID, result.stackSize, result.getItemDamage());
57                                 if(api.getMaterialRecipe().get(i).nbtMatch(par1IInventory) != null){
58                                         ItemStack[] nbtInv = new ItemStack[par3IInventory.getSizeInventory()];
59                                         for(int j = 0;j < par3IInventory.getSizeInventory();j++){
60                                                 nbtInv[j] = par3IInventory.getStackInSlot(j);
61                                         }
62                                         api.getMaterialRecipe().get(i).nbtMatch(par1IInventory).setNBT(nbtInv, resultArg);
63                                 }
64                                 returnObj = api.getMaterialRecipe().get(i).nbtMatch(par1IInventory);
65                         }
66                         par2IInventory.setInventorySlotContents(0, resultArg);
67                 }
68                 return returnObj;
69         }
70
71
72
73         private void clearResults(IInventory par1IInventory, int par2){
74                 /*
75                  * Commented by mozipi.
76                 ((InventoryDecomposition)par1IInventory).setFlag(false);
77                  */
78                 for(int i = 0;i < par2;i++){
79                         par1IInventory.setInventorySlotContents(i, null);
80                 }
81         }
82
83 }