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;
15 public class ChemiCraftCraftingManager {
17 public ItemStack[] getDecompositionResults(IInventory par1IInventory){
19 ((InventoryDecomposition)par1IInventory).setFlag(false);
21 //variable of results.
22 ItemStack[] results = null;
24 //Just loop of amount of added recipe.
25 for(int i1 = 0;i1 < ChemiCraftAPI.instance.getDecompositionMaterial().size();i1++){
29 results = new ItemStack[ChemiCraftAPI.instance.getDecompositionResult().get(i1).length];
31 //Material ID & Damage.
32 int materialID = par1IInventory.getStackInSlot(16).itemID;
33 int materialDamage = par1IInventory.getStackInSlot(16).getItemDamage();
34 int recipeID = ChemiCraftAPI.instance.getDecompositionMaterial().get(i1).itemID;
35 int recipeDamage = ChemiCraftAPI.instance.getDecompositionMaterial().get(i1).getItemDamage();
37 //Check of null of the Material Slot.
38 if(par1IInventory.getStackInSlot(16) == null){ this.clearResults(par1IInventory, 16); return new ItemStack[16];}
40 if(materialID != recipeID){ match = false;}
42 if(materialDamage != recipeDamage){ match = false;}
46 //Just loop of recipe size of recipe index i1.
47 for(int i = 0;i < ChemiCraftAPI.instance.getDecompositionResult().get(i1).length;i++){
48 //Assignment to the results.
49 results[i] = new ItemStack(
50 ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].itemID,
51 ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].stackSize,
52 ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].getItemDamage()
65 public ItemStack getChemicalCombinationResult(IInventory par1IInventory){
67 ((InventoryChemicalCombination) par1IInventory).setFlag(false);
70 ItemStack result = null;
72 //Just loop of amount of added recipe.
73 for(int i = 0;i < ChemiCraftAPI.instance.getChemicalCombinationMaterial().size();i++){
77 //materialID & recipeID
78 ArrayList<Integer> materialID = new ArrayList<Integer>();
79 ArrayList<Integer> materialDamage = new ArrayList<Integer>();
80 ArrayList<Integer> recipeID = new ArrayList<Integer>();
81 ArrayList<Integer> recipeDamage = new ArrayList<Integer>();
83 //Just loop of recipe size of recipe index i.
84 for(int j = 0;j < ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i).length;j++){
85 //Adding the recipe ID & Damage.
86 recipeID.add(ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i)[j].itemID);
87 recipeDamage.add(ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i)[j].getItemDamage());
90 for(int j = 0;j < 16;j++){
92 if(par1IInventory.getStackInSlot(j) != null){
93 //Adding the materialID & Damage.
94 materialID.add(par1IInventory.getStackInSlot(j).itemID);
95 materialDamage.add(par1IInventory.getStackInSlot(j).getItemDamage());
99 //trimToSize & sorting.
100 materialID.trimToSize();
101 materialDamage.trimToSize();
102 recipeID.trimToSize();
103 recipeDamage.trimToSize();
104 Collections.sort(materialID);
105 Collections.sort(materialDamage);
106 Collections.sort(recipeID);
107 Collections.sort(recipeDamage);
110 if(materialID.size() != recipeID.size()){ match = false;}
111 //Just loop of materialID.size().
112 for(int j = 0;j < materialID.size();j++){
114 if(materialID.get(j) != recipeID.get(j)){ match = false;}
116 if(materialDamage.get(j) != recipeDamage.get(j)){ match = false;}
121 //Assignment to the result.
124 ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).itemID,
125 ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).stackSize,
126 ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).getItemDamage()
138 public void chemicalCrafting(InventoryChemicalCraftingMaterial par1IInventory, InventoryChemicalCraftingResult par2IInventory, InventoryChemicalCraftingNBT par3IInventory){
139 ChemiCraftAPI api = ChemiCraftAPI.instance;
140 int[] materialID = new int[par1IInventory.getSizeInventory()];
141 int[] materialDamage = new int[par1IInventory.getSizeInventory()];
142 int[] resultID = new int[par2IInventory.getSizeInventory()];
143 int[] resultDamage = new int[par2IInventory.getSizeInventory()];
144 int[] nbtID = new int[par3IInventory.getSizeInventory()];
145 int[] nbtDamage = new int[par3IInventory.getSizeInventory()];
146 //ItemID,ItemDamageの格納
147 for(int j = 0;j < par1IInventory.getSizeInventory();j++){
148 if(par1IInventory.getStackInSlot(j) != null){
149 materialID[j] = par1IInventory.getStackInSlot(j).itemID;
150 materialDamage[j] = par1IInventory.getStackInSlot(j).getItemDamage();
153 for(int j = 0;j < par2IInventory.getSizeInventory();j++){
154 if(par2IInventory.getStackInSlot(j) != null){
155 resultID[j] = par2IInventory.getStackInSlot(j).itemID;
156 resultDamage[j] = par2IInventory.getStackInSlot(j).getItemDamage();
159 for(int j = 0;j < par3IInventory.getSizeInventory();j++){
160 if(par3IInventory.getStackInSlot(j) != null){
161 nbtID[j] = par3IInventory.getStackInSlot(j).itemID;
162 nbtDamage[j] = par3IInventory.getStackInSlot(j).getItemDamage();
166 for(int i = 0;i < api.getMaterialRecipe().size();i++){
167 api.getMaterialRecipe().get(i).match(par1IInventory);
174 private void clearResults(IInventory par1IInventory, int par2){
175 ((InventoryDecomposition)par1IInventory).setFlag(false);
176 for(int i = 0;i < par2;i++){
177 par1IInventory.setInventorySlotContents(i, null);