OSDN Git Service

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