1 package chemicraft.system;
3 import java.util.ArrayList;
4 import java.util.Collections;
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;
13 public class ChemiCraftCraftingManager {
15 public ItemStack[] getDecompositionResults(IInventory par1IInventory){
17 ((InventoryDecomposition)par1IInventory).setFlag(false);
19 //variable of results.
20 ItemStack[] results = null;
22 //Just loop of amount of added recipe.
23 for(int i1 = 0;i1 < ChemiCraftAPI.instance.getDecompositionMaterial().size();i1++){
27 results = new ItemStack[ChemiCraftAPI.instance.getDecompositionResult().get(i1).length];
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();
35 //Check of null of the Material Slot.
36 if(par1IInventory.getStackInSlot(16) == null){ this.clearResults(par1IInventory, 16); return new ItemStack[16];}
38 if(materialID != recipeID){ match = false;}
40 if(materialDamage != recipeDamage){ match = false;}
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()
63 public ItemStack getChemicalCombinationResult(IInventory par1IInventory){
65 ((InventoryChemicalCombination) par1IInventory).setFlag(false);
68 ItemStack result = null;
70 //Just loop of amount of added recipe.
71 for(int i = 0;i < ChemiCraftAPI.instance.getChemicalCombinationMaterial().size();i++){
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>();
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());
88 for(int j = 0;j < 16;j++){
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());
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);
108 if(materialID.size() != recipeID.size()){ match = false;}
109 //Just loop of materialID.size().
110 for(int j = 0;j < materialID.size();j++){
112 if(materialID.get(j) != recipeID.get(j)){ match = false;}
114 if(materialDamage.get(j) != recipeDamage.get(j)){ match = false;}
119 //Assignment to the result.
122 ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).itemID,
123 ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).stackSize,
124 ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).getItemDamage()
136 public ItemStack getMaterialResult(IInventory par1IInventory){
137 ((InventoryMaterialCrafting) par1IInventory).setFlag(false);
139 ItemStack result = null;
141 for(int i = 0;i < ChemiCraftAPI.instance.getMaterialMaterials().size();i++){
142 boolean match = true;
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];
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());
157 for(int j = 0;j < 9;j++){
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());
166 for(int j = 0;j < 3;j++){
167 var1[j] = par1IInventory.getStackInSlot(j);
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);
181 if(materialID.size() != recipeID.size()){ match = false;}
182 //Just loop of materialID.size().
183 for(int j = 0;j < materialID.size();j++){
185 if(materialID.get(j) != recipeID.get(j)){ match = false;}
187 if(materialDamage.get(j) != recipeDamage.get(j)){ match = false;}
192 //Assignment to the result.
195 ChemiCraftAPI.instance.getMaterialResult().get(i).itemID,
196 ChemiCraftAPI.instance.getMaterialResult().get(i).stackSize,
197 ChemiCraftAPI.instance.getMaterialResult().get(i).getItemDamage()
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);
205 ((InventoryMaterialCrafting) par1IInventory).setFlag2(false);
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);