1 package chemicraft.system;
3 import java.util.ArrayList;
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;
14 public class ChemiCraftCraftingManager {
16 public ItemStack[] getDecompositionResults(IInventory par1IInventory){
19 * Commented by mozipi.
20 ((InventoryDecomposition)par1IInventory).setFlag(false);
23 //variable of results.
24 ItemStack[] results = null;
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];}
33 results = new ItemStack[ChemiCraftAPI.getInstance().getDecompositionResult().get(i1).length];
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();
42 if(materialID != recipeID){ match = false;}
44 if(materialDamage != recipeDamage){ match = false;}
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()
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));
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]);
78 if (var1.length != var2.length) {
81 for (int j = 0; j < var1.length; j++) {
82 if (!var1[j].equals(var2[j])) {
86 return api.getChemicalCombinationResult().get(i);
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;
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);
106 api.getMaterialRecipe().get(i).nbtMatch(par1IInventory).setNBT(nbtInv, resultArg);
108 returnObj = api.getMaterialRecipe().get(i).nbtMatch(par1IInventory);
110 par2IInventory.setInventorySlotContents(0, resultArg);
117 private void clearResults(IInventory par1IInventory, int par2){
119 * Commented by mozipi.
120 ((InventoryDecomposition)par1IInventory).setFlag(false);
122 for(int i = 0;i < par2;i++){
123 par1IInventory.setInventorySlotContents(i, null);