OSDN Git Service

パッケージわけした
[chemicraft/chemicraft.git] / common / chemicraft / system / ChemiCraftCraftingManager.java
1 package chemicraft.system;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5
6 import net.minecraft.src.IInventory;
7 import net.minecraft.src.ItemStack;
8 import chemicraft.ChemiCraftAPI;
9 import chemicraft.inventory.InventoryChemicalCombination;
10 import chemicraft.inventory.InventoryDecomposition;
11 import chemicraft.inventory.InventoryMaterialCrafting;
12
13 public class ChemiCraftCraftingManager {
14
15         public ItemStack[] getDecompositionResults(IInventory par1IInventory){
16                 //Setting to Flag.
17                 ((InventoryDecomposition)par1IInventory).setFlag(false);
18
19                 //variable of results.
20                 ItemStack[] results = null;
21
22                 //Just loop of amount of added recipe.
23                 for(int i1 = 0;i1 < ChemiCraftAPI.instance.getDecompositionMaterial().size();i1++){
24                         //Recipe the match?
25                         boolean match = true;
26                         //Reset the results.
27                         results  = new ItemStack[ChemiCraftAPI.instance.getDecompositionResult().get(i1).length];
28                         //Recipe ID & Damage.
29                         //Material ID & Damage.
30                         int materialID = par1IInventory.getStackInSlot(16).itemID;
31                         int materialDamage = par1IInventory.getStackInSlot(16).getItemDamage();
32                         int recipeID = ChemiCraftAPI.instance.getDecompositionMaterial().get(i1).itemID;
33                         int recipeDamage = ChemiCraftAPI.instance.getDecompositionMaterial().get(i1).getItemDamage();
34
35                         //Check of null of the Material Slot.
36                         if(par1IInventory.getStackInSlot(16) == null){ this.clearResults(par1IInventory, 16); return new ItemStack[16];}
37                         //ID check.
38                         if(materialID != recipeID){ match = false;}
39                         //Damage check.
40                         if(materialDamage != recipeDamage){ match = false;}
41
42                         //if "match == true"
43                         if(match){
44                                 //Just loop of recipe size of recipe index i1.
45                                 for(int i = 0;i < ChemiCraftAPI.instance.getDecompositionResult().get(i1).length;i++){
46                                         //Assignment to the results.
47                                         results[i] = new ItemStack(
48                                                         ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].itemID,
49                                                         ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].stackSize,
50                                                         ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].getItemDamage()
51                                                         );
52                                 }
53                                 //return the results.
54                                 return results;
55                         }
56                 }
57                 //return the null.
58                 return null;
59         }
60
61
62
63         public ItemStack getChemicalCombinationResult(IInventory par1IInventory){
64                 //Setting to flag.
65                 ((InventoryChemicalCombination) par1IInventory).setFlag(false);
66
67                 //variable of result.
68                 ItemStack result = null;
69
70                 //Just loop of amount of added recipe.
71                 for(int i = 0;i < ChemiCraftAPI.instance.getChemicalCombinationMaterial().size();i++){
72
73                         //Recipe the match?
74                         boolean match = true;
75                         //materialID & recipeID
76                         ArrayList<Integer> materialID = new ArrayList<Integer>();
77                         ArrayList<Integer> materialDamage = new ArrayList<Integer>();
78                         ArrayList<Integer> recipeID = new ArrayList<Integer>();
79                         ArrayList<Integer> recipeDamage = new ArrayList<Integer>();
80
81                         //Just loop of recipe size of recipe index i.
82                         for(int j = 0;j < ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i).length;j++){
83                                 //Adding the recipe ID & Damage.
84                                 recipeID.add(ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i)[j].itemID);
85                                 recipeDamage.add(ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i)[j].getItemDamage());
86                         }
87                         //Just loop of 16.
88                         for(int j = 0;j < 16;j++){
89                                 //Null check
90                                 if(par1IInventory.getStackInSlot(j) != null){
91                                         //Adding the materialID & Damage.
92                                         materialID.add(par1IInventory.getStackInSlot(j).itemID);
93                                         materialDamage.add(par1IInventory.getStackInSlot(j).getItemDamage());
94                                 }
95                         }
96
97                         //trimToSize & sorting.
98                         materialID.trimToSize();
99                         materialDamage.trimToSize();
100                         recipeID.trimToSize();
101                         recipeDamage.trimToSize();
102                         Collections.sort(materialID);
103                         Collections.sort(materialDamage);
104                         Collections.sort(recipeID);
105                         Collections.sort(recipeDamage);
106
107                         //Size check.
108                         if(materialID.size() != recipeID.size()){ match = false;}
109                         //Just loop of materialID.size().
110                         for(int j = 0;j < materialID.size();j++){
111                                 //ID check.
112                                 if(materialID.get(j) != recipeID.get(j)){ match = false;}
113                                 //Damage check.
114                                 if(materialDamage.get(j) != recipeDamage.get(j)){ match = false;}
115                         }
116
117                         //if "match == true"
118                         if(match){
119                                 //Assignment to the result.
120                                 result =
121                                                 new ItemStack(
122                                                                 ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).itemID,
123                                                                 ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).stackSize,
124                                                                 ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).getItemDamage()
125                                                                 );
126                                 //return the result.
127                                 return result;
128                         }
129                 }
130                 //return the null.
131                 return null;
132         }
133
134
135
136         public ItemStack getMaterialResult(IInventory par1IInventory){
137                 ((InventoryMaterialCrafting) par1IInventory).setFlag(false);
138
139                 ItemStack result = null;
140
141                 for(int i = 0;i < ChemiCraftAPI.instance.getMaterialMaterials().size();i++){
142                         boolean match = true;
143
144                         ArrayList<Integer> materialID = new ArrayList<Integer>();
145                         ArrayList<Integer> materialDamage = new ArrayList<Integer>();
146                         ArrayList<Integer> recipeID = new ArrayList<Integer>();
147                         ArrayList<Integer> recipeDamage = new ArrayList<Integer>();
148                         ItemStack[] var1 = new ItemStack[3];
149
150                         //Just loop of recipe size of recipe index i.
151                         for(int j = 0;j < ChemiCraftAPI.instance.getMaterialMaterials().get(i).length;j++){
152                                 //Adding the recipe ID & Damage.
153                                 recipeID.add(ChemiCraftAPI.instance.getMaterialMaterials().get(i)[j].itemID);
154                                 recipeDamage.add(ChemiCraftAPI.instance.getMaterialMaterials().get(i)[j].getItemDamage());
155                         }
156                         //Just loop of 9.
157                         for(int j = 0;j < 9;j++){
158                                 //Null check
159                                 if(par1IInventory.getStackInSlot(j+3) != null){
160                                         //Adding the materialID & Damage.
161                                         materialID.add(par1IInventory.getStackInSlot(j+3).itemID);
162                                         materialDamage.add(par1IInventory.getStackInSlot(j+3).getItemDamage());
163                                 }
164                         }
165
166                         for(int j = 0;j < 3;j++){
167                                 var1[j] = par1IInventory.getStackInSlot(j);
168                         }
169
170                         //trimToSize & sorting.
171                         materialID.trimToSize();
172                         materialDamage.trimToSize();
173                         recipeID.trimToSize();
174                         recipeDamage.trimToSize();
175                         Collections.sort(materialID);
176                         Collections.sort(materialDamage);
177                         Collections.sort(recipeID);
178                         Collections.sort(recipeDamage);
179
180                         //Size check.
181                         if(materialID.size() != recipeID.size()){ match = false;}
182                         //Just loop of materialID.size().
183                         for(int j = 0;j < materialID.size();j++){
184                                 //ID check.
185                                 if(materialID.get(j) != recipeID.get(j)){ match = false;}
186                                 //Damage check.
187                                 if(materialDamage.get(j) != recipeDamage.get(j)){ match = false;}
188                         }
189
190                         //if "match == true"
191                         if(match){
192                                 //Assignment to the result.
193                                 result =
194                                                 new ItemStack(
195                                                                 ChemiCraftAPI.instance.getMaterialResult().get(i).itemID,
196                                                                 ChemiCraftAPI.instance.getMaterialResult().get(i).stackSize,
197                                                                 ChemiCraftAPI.instance.getMaterialResult().get(i).getItemDamage()
198                                                                 );
199
200                                 if(ChemiCraftAPI.instance.getMaterialNBTRecipe().get(i) != null){
201                                         ItemStack[] useItems = ChemiCraftAPI.instance.getMaterialNBTRecipe().get(i).setNBT(var1, result);
202                                         ((InventoryMaterialCrafting) par1IInventory).subtractStack(0, 3, useItems);
203                                 }
204
205                                 ((InventoryMaterialCrafting) par1IInventory).setFlag2(false);
206
207                                 //return the result.
208                                 return result;
209                         }
210                 }
211
212                 return null;
213         }
214
215
216
217         private void clearResults(IInventory par1IInventory, int par2){
218                 ((InventoryDecomposition)par1IInventory).setFlag(false);
219                 for(int i = 0;i < par2;i++){
220                         par1IInventory.setInventorySlotContents(i, null);
221                 }
222         }
223
224 }