OSDN Git Service

化合台完成
[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                 //Setting to Flag.
18                 /*
19                  * Commented by mozipi.
20                 ((InventoryDecomposition)par1IInventory).setFlag(false);
21                  */
22
23                 //variable of results.
24                 ItemStack[] results = null;
25
26                 //Just loop of amount of added recipe.
27                 for(int i1 = 0;i1 < ChemiCraftAPI.getInstance().getDecompositionMaterial().size();i1++){
28                         //Check of null of the Material Slot.
29                         if(par1IInventory.getStackInSlot(16) == null){ this.clearResults(par1IInventory, 16); return new ItemStack[16];}
30                         //Recipe the match?
31                         boolean match = true;
32                         //Reset the results.
33                         results  = new ItemStack[ChemiCraftAPI.getInstance().getDecompositionResult().get(i1).length];
34                         //Recipe ID & Damage.
35                         //Material ID & Damage.
36                         int materialID = par1IInventory.getStackInSlot(16).itemID;
37                         int materialDamage = par1IInventory.getStackInSlot(16).getItemDamage();
38                         int recipeID = ChemiCraftAPI.getInstance().getDecompositionMaterial().get(i1).itemID;
39                         int recipeDamage = ChemiCraftAPI.getInstance().getDecompositionMaterial().get(i1).getItemDamage();
40
41                         //ID check.
42                         if(materialID != recipeID){ match = false;}
43                         //Damage check.
44                         if(materialDamage != recipeDamage){ match = false;}
45
46                         //if "match == true"
47                         if(match){
48                                 //Just loop of recipe size of recipe index i1.
49                                 for(int i = 0;i < ChemiCraftAPI.getInstance().getDecompositionResult().get(i1).length;i++){
50                                         //Assignment to the results.
51                                         results[i] = new ItemStack(
52                                                         ChemiCraftAPI.getInstance().getDecompositionResult().get(i1)[i].itemID,
53                                                         ChemiCraftAPI.getInstance().getDecompositionResult().get(i1)[i].stackSize,
54                                                         ChemiCraftAPI.getInstance().getDecompositionResult().get(i1)[i].getItemDamage()
55                                                         );
56                                 }
57                                 //return the results.
58                                 return results;
59                         }
60                 }
61                 //return the null.
62                 return null;
63         }
64
65
66
67         public ItemStack getChemicalCombinationResult(ArrayList<String> atomsList, ArrayList<Integer> atomsAmountList){
68                 ChemiCraftAPI api = ChemiCraftAPI.getInstance();
69                 for (int i = 0; i < api.getChemicalCombinationAtoms().size(); i++) {
70                         FormulaPart[] var1 = new FormulaPart[atomsList.size()];
71                         FormulaPart[] var2 = new FormulaPart[api.getChemicalCombinationAtoms().get(i).length];
72                         for (int j = 0; j < atomsList.size(); j++) {
73                                 var1[j] = new FormulaPart(atomsList.get(j), atomsAmountList.get(j));
74                         }
75                         for (int j = 0; j < api.getChemicalCombinationAtoms().get(i).length; j++) {
76                                 var2[j] = new FormulaPart(api.getChemicalCombinationAtoms().get(i)[j], api.getChemicalCombinationAmounts().get(i)[j]);
77                         }
78                         if (var1.length != var2.length) {
79                                 continue;
80                         }
81                         for (int j = 0; j < var1.length; j++) {
82                                 if (!var1[j].equals(var2[j])) {
83                                         continue;
84                                 }
85                         }
86                         return api.getChemicalCombinationResult().get(i);
87                 }
88                 return null;
89         }
90
91
92
93         public ChemicalNBTRecipe chemicalCrafting(InventoryChemicalCraftingMaterial par1IInventory, InventoryChemicalCraftingResult par2IInventory, InventoryChemicalCraftingNBT par3IInventory){
94                 ChemiCraftAPI api = ChemiCraftAPI.getInstance();
95                 ChemicalNBTRecipe returnObj = null;
96                 for(int i = 0;i < api.getMaterialRecipe().size();i++){
97                         ItemStack result = api.getMaterialRecipe().get(i).match(par1IInventory);
98                         ItemStack resultArg = null;
99                         if(result != null){
100                                 resultArg = new ItemStack(result.itemID, result.stackSize, result.getItemDamage());
101                                 if(api.getMaterialRecipe().get(i).nbtMatch(par1IInventory) != null){
102                                         ItemStack[] nbtInv = new ItemStack[par3IInventory.getSizeInventory()];
103                                         for(int j = 0;j < par3IInventory.getSizeInventory();j++){
104                                                 nbtInv[j] = par3IInventory.getStackInSlot(j);
105                                         }
106                                         api.getMaterialRecipe().get(i).nbtMatch(par1IInventory).setNBT(nbtInv, resultArg);
107                                 }
108                                 returnObj = api.getMaterialRecipe().get(i).nbtMatch(par1IInventory);
109                         }
110                         par2IInventory.setInventorySlotContents(0, resultArg);
111                 }
112                 return returnObj;
113         }
114
115
116
117         private void clearResults(IInventory par1IInventory, int par2){
118                 /*
119                  * Commented by mozipi.
120                 ((InventoryDecomposition)par1IInventory).setFlag(false);
121                  */
122                 for(int i = 0;i < par2;i++){
123                         par1IInventory.setInventorySlotContents(i, null);
124                 }
125         }
126
127 }