OSDN Git Service

パッケージをpcc.chemicraft.*に変更
[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 import java.util.Collections;
6
7 import net.minecraft.inventory.IInventory;
8 import net.minecraft.item.ItemStack;
9 import pcc.chemicraft.ChemiCraft;
10 import pcc.chemicraft.ChemiCraftAPI;
11 import pcc.chemicraft.inventory.InventoryChemicalCraftingMaterial;
12 import pcc.chemicraft.inventory.InventoryChemicalCraftingNBT;
13 import pcc.chemicraft.inventory.InventoryChemicalCraftingResult;
14 import pcc.chemicraft.inventory.InventoryToolAndWeaponCraftingTableMaterial;
15 import pcc.chemicraft.util.ChemicalNBTRecipe;
16 import pcc.chemicraft.util.ComparatorFormulaPart;
17 import pcc.chemicraft.util.ComparatorItemStack;
18 import pcc.chemicraft.util.FormulaPart;
19
20 public class ChemiCraftCraftingManager {
21
22         public ItemStack getToolAndWeaponCraftingResult(InventoryToolAndWeaponCraftingTableMaterial par1IInventory){
23                 ChemiCraftAPI api = ChemiCraftAPI.getInstance();
24                 ArrayList<ItemStack[]> materials = api.getToolAndWeaponMaterials();
25                 ArrayList<ItemStack> result = api.getToolAndWeaponResult();
26                 ArrayList<Boolean> sharpless = api.getToolAndWeaponSharpless();
27
28                 ItemStack[] slotItems = new ItemStack[par1IInventory.getSizeInventory()];
29                 for (int i = 0; i < par1IInventory.getSizeInventory(); i++) {
30                         slotItems[i] = (par1IInventory.getStackInSlot(i));
31                 }
32
33                 label1 :
34                         for (int i = 0; i < materials.size(); i++) {
35                                 if (sharpless.get(i)) {
36                                         slotItems = ChemiCraft.instance.arrayAuxiliary.deleteNull(slotItems);
37                                         Collections.sort(materials, new ComparatorItemStack());
38                                         Arrays.sort(slotItems, new ComparatorItemStack());
39                                         if (materials.size() != slotItems.length) continue label1;
40
41                                         for (int j = 0; j < materials.size(); j++) {
42                                                 if (materials.get(i)[j].itemID != slotItems[j].itemID) {
43                                                         if (materials.get(i)[j].getItemDamage() != slotItems[j].getItemDamage()) {
44                                                                 continue label1;
45                                                         }
46                                                 }
47                                         }
48                                         return result.get(i);
49                                 } else {
50                                         slotItems = ChemiCraft.instance.arrayAuxiliary.deleteNull(slotItems);
51                                         if (materials.get(i).length != slotItems.length) continue label1;
52
53                                         for (int j = 0; j < materials.size(); j++) {
54                                                 if (materials.get(i)[j].itemID != slotItems[j].itemID) {
55                                                         if (materials.get(i)[j].getItemDamage() != slotItems[j].getItemDamage()) {
56                                                                 continue label1;
57                                                         }
58                                                 }
59                                         }
60                                         return result.get(i);
61                                 }
62                         }
63                 return null;
64         }
65
66
67
68         public ItemStack getChemicalCombinationResult(ArrayList<String> atomsList, ArrayList<Integer> atomsAmountList){
69                 ChemiCraftAPI api = ChemiCraftAPI.getInstance();
70                 recipeSize :
71                         for (int i = 0; i < api.getChemicalCombinationAtoms().size(); i++) {
72                                 FormulaPart[] var1 = new FormulaPart[atomsList.size()];
73                                 FormulaPart[] var2 = new FormulaPart[api.getChemicalCombinationAtoms().get(i).length];
74                                 for (int j = 0; j < atomsList.size(); j++) {
75                                         var1[j] = new FormulaPart(atomsList.get(j), atomsAmountList.get(j));
76                                 }
77                                 for (int j = 0; j < api.getChemicalCombinationAtoms().get(i).length; j++) {
78                                         var2[j] = new FormulaPart(api.getChemicalCombinationAtoms().get(i)[j], api.getChemicalCombinationAmounts().get(i)[j]);
79                                 }
80                                 Arrays.sort(var1, new ComparatorFormulaPart());
81                                 Arrays.sort(var2, new ComparatorFormulaPart());
82                                 if (var1.length != var2.length) {
83                                         continue recipeSize;
84                                 }
85                                 for (int j = 0; j < var1.length; j++) {
86                                         if (!var1[j].equals(var2[j])) {
87                                                 continue recipeSize;
88                                         }
89                                 }
90                                 return api.getChemicalCombinationResult().get(i);
91                         }
92                 return null;
93         }
94
95
96
97         public ChemicalNBTRecipe chemicalCrafting(InventoryChemicalCraftingMaterial par1IInventory, InventoryChemicalCraftingResult par2IInventory, InventoryChemicalCraftingNBT par3IInventory){
98                 ChemiCraftAPI api = ChemiCraftAPI.getInstance();
99                 ChemicalNBTRecipe returnObj = null;
100                 for(int i = 0;i < api.getMaterialRecipe().size();i++){
101                         ItemStack result = api.getMaterialRecipe().get(i).match(par1IInventory);
102                         ItemStack resultArg = null;
103                         if(result != null){
104                                 resultArg = new ItemStack(result.itemID, result.stackSize, result.getItemDamage());
105                                 if(api.getMaterialRecipe().get(i).nbtMatch(par1IInventory) != null){
106                                         ItemStack[] nbtInv = new ItemStack[par3IInventory.getSizeInventory()];
107                                         for(int j = 0;j < par3IInventory.getSizeInventory();j++){
108                                                 nbtInv[j] = par3IInventory.getStackInSlot(j);
109                                         }
110                                         api.getMaterialRecipe().get(i).nbtMatch(par1IInventory).setNBT(nbtInv, resultArg);
111                                 }
112                                 returnObj = api.getMaterialRecipe().get(i).nbtMatch(par1IInventory);
113                         }
114                         par2IInventory.setInventorySlotContents(0, resultArg);
115                 }
116                 return returnObj;
117         }
118
119
120
121         private void clearResults(IInventory par1IInventory, int par2){
122                 /*
123                  * Commented by mozipi.
124                 ((InventoryDecomposition)par1IInventory).setFlag(false);
125                  */
126                 for(int i = 0;i < par2;i++){
127                         par1IInventory.setInventorySlotContents(i, null);
128                 }
129         }
130
131 }