OSDN Git Service

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