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.InventoryChemicalCraftingMaterial;
11 import chemicraft.inventory.InventoryChemicalCraftingNBT;
12 import chemicraft.inventory.InventoryChemicalCraftingResult;
13 import chemicraft.inventory.InventoryDecomposition;
14 import chemicraft.util.ChemicalNBTRecipe;
16 public class ChemiCraftCraftingManager {
18 public ItemStack[] getDecompositionResults(IInventory par1IInventory){
20 ((InventoryDecomposition)par1IInventory).setFlag(false);
22 //variable of results.
23 ItemStack[] results = null;
25 //Just loop of amount of added recipe.
26 for(int i1 = 0;i1 < ChemiCraftAPI.instance.getDecompositionMaterial().size();i1++){
27 //Check of null of the Material Slot.
28 if(par1IInventory.getStackInSlot(16) == null){ this.clearResults(par1IInventory, 16); return new ItemStack[16];}
32 results = new ItemStack[ChemiCraftAPI.instance.getDecompositionResult().get(i1).length];
34 //Material ID & Damage.
35 int materialID = par1IInventory.getStackInSlot(16).itemID;
36 int materialDamage = par1IInventory.getStackInSlot(16).getItemDamage();
37 int recipeID = ChemiCraftAPI.instance.getDecompositionMaterial().get(i1).itemID;
38 int recipeDamage = ChemiCraftAPI.instance.getDecompositionMaterial().get(i1).getItemDamage();
41 if(materialID != recipeID){ match = false;}
43 if(materialDamage != recipeDamage){ match = false;}
47 //Just loop of recipe size of recipe index i1.
48 for(int i = 0;i < ChemiCraftAPI.instance.getDecompositionResult().get(i1).length;i++){
49 //Assignment to the results.
50 results[i] = new ItemStack(
51 ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].itemID,
52 ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].stackSize,
53 ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].getItemDamage()
66 public ItemStack getChemicalCombinationResult(IInventory par1IInventory){
68 ((InventoryChemicalCombination) par1IInventory).setFlag(false);
71 ItemStack result = null;
73 //Just loop of amount of added recipe.
74 for(int i = 0;i < ChemiCraftAPI.instance.getChemicalCombinationMaterial().size();i++){
78 //materialID & recipeID
79 ArrayList<Integer> materialID = new ArrayList<Integer>();
80 ArrayList<Integer> materialDamage = new ArrayList<Integer>();
81 ArrayList<Integer> recipeID = new ArrayList<Integer>();
82 ArrayList<Integer> recipeDamage = new ArrayList<Integer>();
84 //Just loop of recipe size of recipe index i.
85 for(int j = 0;j < ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i).length;j++){
86 //Adding the recipe ID & Damage.
87 recipeID.add(ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i)[j].itemID);
88 recipeDamage.add(ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i)[j].getItemDamage());
91 for(int j = 0;j < 16;j++){
93 if(par1IInventory.getStackInSlot(j) != null){
94 //Adding the materialID & Damage.
95 materialID.add(par1IInventory.getStackInSlot(j).itemID);
96 materialDamage.add(par1IInventory.getStackInSlot(j).getItemDamage());
100 //trimToSize & sorting.
101 materialID.trimToSize();
102 materialDamage.trimToSize();
103 recipeID.trimToSize();
104 recipeDamage.trimToSize();
105 Collections.sort(materialID);
106 Collections.sort(materialDamage);
107 Collections.sort(recipeID);
108 Collections.sort(recipeDamage);
111 if(materialID.size() != recipeID.size()){ match = false;}
112 //Just loop of materialID.size().
113 for(int j = 0;j < materialID.size();j++){
115 if(materialID.get(j) != recipeID.get(j)){ match = false;}
117 if(materialDamage.get(j) != recipeDamage.get(j)){ match = false;}
122 //Assignment to the result.
125 ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).itemID,
126 ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).stackSize,
127 ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).getItemDamage()
139 public ChemicalNBTRecipe chemicalCrafting(InventoryChemicalCraftingMaterial par1IInventory, InventoryChemicalCraftingResult par2IInventory, InventoryChemicalCraftingNBT par3IInventory){
140 ChemiCraftAPI api = ChemiCraftAPI.instance;
141 ChemicalNBTRecipe returnObj = null;
142 for(int i = 0;i < api.getMaterialRecipe().size();i++){
143 ItemStack result = api.getMaterialRecipe().get(i).match(par1IInventory);
144 ItemStack resultArg = null;
146 resultArg = new ItemStack(result.itemID, result.stackSize, result.getItemDamage());
147 if(api.getMaterialRecipe().get(i).nbtMatch(par1IInventory) != null){
148 ItemStack[] nbtInv = new ItemStack[par3IInventory.getSizeInventory()];
149 for(int j = 0;j < par3IInventory.getSizeInventory();j++){
150 nbtInv[j] = par3IInventory.getStackInSlot(j);
152 api.getMaterialRecipe().get(i).nbtMatch(par1IInventory).setNBT(nbtInv, resultArg);
154 returnObj = api.getMaterialRecipe().get(i).nbtMatch(par1IInventory);
156 par2IInventory.setInventorySlotContents(0, resultArg);
163 private void clearResults(IInventory par1IInventory, int par2){
164 ((InventoryDecomposition)par1IInventory).setFlag(false);
165 for(int i = 0;i < par2;i++){
166 par1IInventory.setInventorySlotContents(i, null);