1 package pcc.chemicraft.system;
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.Collections;
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;
21 public class ChemiCraftCraftingManager {
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();
29 ItemStack[] slotItems = new ItemStack[par1IInventory.getSizeInventory()];
30 for (int i = 0; i < par1IInventory.getSizeInventory(); i++) {
31 slotItems[i] = (par1IInventory.getStackInSlot(i));
35 for (int i = 0; i < materials.size(); i++) {
36 if (sharpless.get(i)) {
37 slotItems = ChemiCraft.instance.arrayAuxiliary.deleteNull(slotItems);
38 Collections.sort(materials, new ComparatorItemStack());
39 Arrays.sort(slotItems, new ComparatorItemStack());
40 if (materials.size() != slotItems.length) continue label1;
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()) {
51 slotItems = ChemiCraft.instance.arrayAuxiliary.deleteNull(slotItems);
52 if (materials.get(i).length != slotItems.length) continue label1;
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()) {
69 public ItemStack getChemicalCombinationResult(ArrayList<String> atomsList, ArrayList<Integer> atomsAmountList){
70 ChemiCraftAPI api = ChemiCraftAPI.instance();
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));
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]);
81 Arrays.sort(var1, new ComparatorFormulaPart());
82 Arrays.sort(var2, new ComparatorFormulaPart());
83 if (var1.length != var2.length) {
86 for (int j = 0; j < var1.length; j++) {
87 if (!var1[j].equals(var2[j])) {
91 return api.getChemicalCombinationResult().get(i);
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;
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);
111 api.getMaterialRecipe().get(i).nbtMatch(par1IInventory).setNBT(nbtInv, resultArg);
113 returnObj = api.getMaterialRecipe().get(i).nbtMatch(par1IInventory);
115 par2IInventory.setInventorySlotContents(0, resultArg);
122 private void clearResults(IInventory par1IInventory, int par2){
124 * Commented by mozipi.
125 ((InventoryDecomposition)par1IInventory).setFlag(false);
127 for(int i = 0;i < par2;i++){
128 par1IInventory.setInventorySlotContents(i, null);