3 import java.util.ArrayList;
4 import java.util.Collections;
6 import net.minecraft.src.IInventory;
7 import net.minecraft.src.ItemStack;
9 public class ChemiCraftCraftingManager {
11 public ItemStack[] getDecompositionResults(IInventory par1IInventory){
13 ((InventoryDecomposition)par1IInventory).setFlag(false);
15 //variable of results.
16 ItemStack[] results = null;
18 //Just loop of amount of added recipe.
19 for(int i1 = 0;i1 < ChemiCraftAPI.instance.getDecompositionMaterial().size();i1++){
23 results = new ItemStack[ChemiCraftAPI.instance.getDecompositionResult().get(i1).length];
25 //Material ID & Damage.
26 int materialID = par1IInventory.getStackInSlot(16).itemID;
27 int materialDamage = par1IInventory.getStackInSlot(16).getItemDamage();
28 int recipeID = ChemiCraftAPI.instance.getDecompositionMaterial().get(i1).itemID;
29 int recipeDamage = ChemiCraftAPI.instance.getDecompositionMaterial().get(i1).getItemDamage();
31 //Check of null of the Material Slot.
32 if(par1IInventory.getStackInSlot(16) == null){ this.clearResults(par1IInventory, 16); return new ItemStack[16];}
34 if(materialID != recipeID){ match = false;}
36 if(materialDamage != recipeDamage){ match = false;}
40 //Just loop of recipe size of recipe index i1.
41 for(int i = 0;i < ChemiCraftAPI.instance.getDecompositionResult().get(i1).length;i++){
42 //Assignment to the results.
43 results[i] = new ItemStack(
44 ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].itemID,
45 ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].stackSize,
46 ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].getItemDamage()
59 public ItemStack getChemicalCombinationResult(IInventory par1IInventory){
61 ((InventoryChemicalCombination) par1IInventory).setFlag(false);
64 ItemStack result = null;
66 //Just loop of amount of added recipe.
67 for(int i = 0;i < ChemiCraftAPI.instance.getChemicalCombinationMaterial().size();i++){
71 //materialID & recipeID
72 ArrayList<Integer> materialID = new ArrayList<Integer>();
73 ArrayList<Integer> materialDamage = new ArrayList<Integer>();
74 ArrayList<Integer> recipeID = new ArrayList<Integer>();
75 ArrayList<Integer> recipeDamage = new ArrayList<Integer>();
77 //Just loop of recipe size of recipe index i.
78 for(int j = 0;j < ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i).length;j++){
79 //Adding the recipe ID & Damage.
80 recipeID.add(ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i)[j].itemID);
81 recipeDamage.add(ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i)[j].getItemDamage());
84 for(int j = 0;j < 16;j++){
86 if(par1IInventory.getStackInSlot(j) != null){
87 //Adding the materialID & Damage.
88 materialID.add(par1IInventory.getStackInSlot(j).itemID);
89 materialDamage.add(par1IInventory.getStackInSlot(j).getItemDamage());
93 //trimToSize & sorting.
94 materialID.trimToSize();
95 materialDamage.trimToSize();
96 recipeID.trimToSize();
97 recipeDamage.trimToSize();
98 Collections.sort(materialID);
99 Collections.sort(materialDamage);
100 Collections.sort(recipeID);
101 Collections.sort(recipeDamage);
104 if(materialID.size() != recipeID.size()){ match = false;}
105 //Just loop of materialID.size().
106 for(int j = 0;j < materialID.size();j++){
108 if(materialID.get(j) != recipeID.get(j)){ match = false;}
110 if(materialDamage.get(j) != recipeDamage.get(j)){ match = false;}
115 //Assignment to the result.
118 ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).itemID,
119 ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).stackSize,
120 ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).getItemDamage()
132 public ItemStack getMaterialResult(IInventory par1IInventory){
133 ((InventoryMaterialCrafting) par1IInventory).setFlag(false);
135 ItemStack result = null;
137 for(int i = 0;i < ChemiCraftAPI.instance.getMaterialMaterials().size();i++){
138 boolean match = true;
140 ArrayList<Integer> materialID = new ArrayList<Integer>();
141 ArrayList<Integer> materialDamage = new ArrayList<Integer>();
142 ArrayList<Integer> recipeID = new ArrayList<Integer>();
143 ArrayList<Integer> recipeDamage = new ArrayList<Integer>();
144 ItemStack[] var1 = new ItemStack[3];
146 //Just loop of recipe size of recipe index i.
147 for(int j = 0;j < ChemiCraftAPI.instance.getMaterialMaterials().get(i).length;j++){
148 //Adding the recipe ID & Damage.
149 recipeID.add(ChemiCraftAPI.instance.getMaterialMaterials().get(i)[j].itemID);
150 recipeDamage.add(ChemiCraftAPI.instance.getMaterialMaterials().get(i)[j].getItemDamage());
153 for(int j = 0;j < 9;j++){
155 if(par1IInventory.getStackInSlot(j+3) != null){
156 //Adding the materialID & Damage.
157 materialID.add(par1IInventory.getStackInSlot(j+3).itemID);
158 materialDamage.add(par1IInventory.getStackInSlot(j+3).getItemDamage());
162 for(int j = 0;j < 3;j++){
163 var1[j] = par1IInventory.getStackInSlot(j);
166 //trimToSize & sorting.
167 materialID.trimToSize();
168 materialDamage.trimToSize();
169 recipeID.trimToSize();
170 recipeDamage.trimToSize();
171 Collections.sort(materialID);
172 Collections.sort(materialDamage);
173 Collections.sort(recipeID);
174 Collections.sort(recipeDamage);
177 if(materialID.size() != recipeID.size()){ match = false;}
178 //Just loop of materialID.size().
179 for(int j = 0;j < materialID.size();j++){
181 if(materialID.get(j) != recipeID.get(j)){ match = false;}
183 if(materialDamage.get(j) != recipeDamage.get(j)){ match = false;}
188 //Assignment to the result.
191 ChemiCraftAPI.instance.getMaterialResult().get(i).itemID,
192 ChemiCraftAPI.instance.getMaterialResult().get(i).stackSize,
193 ChemiCraftAPI.instance.getMaterialResult().get(i).getItemDamage()
196 if(ChemiCraftAPI.instance.getMaterialNBTRecipe().get(i) != null){
197 ItemStack[] useItems = ChemiCraftAPI.instance.getMaterialNBTRecipe().get(i).setNBT(var1, result);
198 ((InventoryMaterialCrafting) par1IInventory).subtractStack(0, 3, useItems);
201 ((InventoryMaterialCrafting) par1IInventory).setFlag2(false);
213 private void clearResults(IInventory par1IInventory, int par2){
214 ((InventoryDecomposition)par1IInventory).setFlag(false);
215 for(int i = 0;i < par2;i++){
216 par1IInventory.setInventorySlotContents(i, null);