OSDN Git Service

修正・変更
[chemicraft/chemicraft.git] / common / pcc / chemicraft / system / ChemiCraftCraftingManager.java
1 package pcc.chemicraft.system;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5
6 import pcc.chemicraft.ChemiCraftAPI;
7 import pcc.chemicraft.inventory.InventoryChemicalCraftingMaterial;
8 import pcc.chemicraft.inventory.InventoryChemicalCraftingNBT;
9 import pcc.chemicraft.inventory.InventoryChemicalCraftingResult;
10 import pcc.chemicraft.util.ChemicalNBTRecipe;
11 import pcc.chemicraft.util.ComparatorFormulaPart;
12 import pcc.chemicraft.util.FormulaPart;
13
14 import net.minecraft.inventory.IInventory;
15 import net.minecraft.item.ItemStack;
16
17 public class ChemiCraftCraftingManager {
18
19         public ItemStack[] getDecompositionResults(IInventory par1IInventory){
20                 return null;
21         }
22
23
24
25         public ItemStack getChemicalCombinationResult(ArrayList<String> atomsList, ArrayList<Integer> atomsAmountList){
26                 ChemiCraftAPI api = ChemiCraftAPI.instance();
27                 recipeSize :
28                         for (int i = 0; i < api.getChemicalCombinationAtoms().size(); i++) {
29                                 FormulaPart[] var1 = new FormulaPart[atomsList.size()];
30                                 FormulaPart[] var2 = new FormulaPart[api.getChemicalCombinationAtoms().get(i).length];
31                                 for (int j = 0; j < atomsList.size(); j++) {
32                                         var1[j] = new FormulaPart(atomsList.get(j), atomsAmountList.get(j));
33                                 }
34                                 for (int j = 0; j < api.getChemicalCombinationAtoms().get(i).length; j++) {
35                                         var2[j] = new FormulaPart(api.getChemicalCombinationAtoms().get(i)[j], api.getChemicalCombinationAmounts().get(i)[j]);
36                                 }
37                                 Arrays.sort(var1, new ComparatorFormulaPart());
38                                 Arrays.sort(var2, new ComparatorFormulaPart());
39                                 if (var1.length != var2.length) {
40                                         continue recipeSize;
41                                 }
42                                 for (int j = 0; j < var1.length; j++) {
43                                         if (!var1[j].equals(var2[j])) {
44                                                 continue recipeSize;
45                                         }
46                                 }
47                                 return api.getChemicalCombinationResult().get(i);
48                         }
49                 return null;
50         }
51
52
53
54         public ChemicalNBTRecipe chemicalCrafting(InventoryChemicalCraftingMaterial par1IInventory, InventoryChemicalCraftingResult par2IInventory, InventoryChemicalCraftingNBT par3IInventory){
55                 ChemiCraftAPI api = ChemiCraftAPI.instance();
56                 ChemicalNBTRecipe returnObj = null;
57                 for(int i = 0;i < api.getMaterialRecipe().size();i++){
58                         ItemStack result = api.getMaterialRecipe().get(i).match(par1IInventory);
59                         ItemStack resultArg = null;
60                         if(result != null){
61                                 resultArg = new ItemStack(result.itemID, result.stackSize, result.getItemDamage());
62                                 if(api.getMaterialRecipe().get(i).nbtMatch(par1IInventory) != null){
63                                         ItemStack[] nbtInv = new ItemStack[par3IInventory.getSizeInventory()];
64                                         for(int j = 0;j < par3IInventory.getSizeInventory();j++){
65                                                 nbtInv[j] = par3IInventory.getStackInSlot(j);
66                                         }
67                                         api.getMaterialRecipe().get(i).nbtMatch(par1IInventory).setNBT(nbtInv, resultArg);
68                                 }
69                                 returnObj = api.getMaterialRecipe().get(i).nbtMatch(par1IInventory);
70                         }
71                         par2IInventory.setInventorySlotContents(0, resultArg);
72                 }
73                 return returnObj;
74         }
75
76
77
78         private void clearResults(IInventory par1IInventory, int par2){
79                 /*
80                  * Commented by mozipi.
81                 ((InventoryDecomposition)par1IInventory).setFlag(false);
82                  */
83                 for(int i = 0;i < par2;i++){
84                         par1IInventory.setInventorySlotContents(i, null);
85                 }
86         }
87
88 }