package chemicraft.system;
import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Arrays;
-import net.minecraft.src.IInventory;
-import net.minecraft.src.ItemStack;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.item.ItemStack;
import chemicraft.ChemiCraftAPI;
-import chemicraft.inventory.InventoryChemicalCombination;
import chemicraft.inventory.InventoryChemicalCraftingMaterial;
import chemicraft.inventory.InventoryChemicalCraftingNBT;
import chemicraft.inventory.InventoryChemicalCraftingResult;
-import chemicraft.inventory.InventoryDecomposition;
+import chemicraft.util.ChemicalNBTRecipe;
+import chemicraft.util.ComparatorFormulaPart;
+import chemicraft.util.FormulaPart;
public class ChemiCraftCraftingManager {
public ItemStack[] getDecompositionResults(IInventory par1IInventory){
- //Setting to Flag.
- ((InventoryDecomposition)par1IInventory).setFlag(false);
-
- //variable of results.
- ItemStack[] results = null;
-
- //Just loop of amount of added recipe.
- for(int i1 = 0;i1 < ChemiCraftAPI.instance.getDecompositionMaterial().size();i1++){
- //Recipe the match?
- boolean match = true;
- //Reset the results.
- results = new ItemStack[ChemiCraftAPI.instance.getDecompositionResult().get(i1).length];
- //Recipe ID & Damage.
- //Material ID & Damage.
- int materialID = par1IInventory.getStackInSlot(16).itemID;
- int materialDamage = par1IInventory.getStackInSlot(16).getItemDamage();
- int recipeID = ChemiCraftAPI.instance.getDecompositionMaterial().get(i1).itemID;
- int recipeDamage = ChemiCraftAPI.instance.getDecompositionMaterial().get(i1).getItemDamage();
-
- //Check of null of the Material Slot.
- if(par1IInventory.getStackInSlot(16) == null){ this.clearResults(par1IInventory, 16); return new ItemStack[16];}
- //ID check.
- if(materialID != recipeID){ match = false;}
- //Damage check.
- if(materialDamage != recipeDamage){ match = false;}
-
- //if "match == true"
- if(match){
- //Just loop of recipe size of recipe index i1.
- for(int i = 0;i < ChemiCraftAPI.instance.getDecompositionResult().get(i1).length;i++){
- //Assignment to the results.
- results[i] = new ItemStack(
- ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].itemID,
- ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].stackSize,
- ChemiCraftAPI.instance.getDecompositionResult().get(i1)[i].getItemDamage()
- );
- }
- //return the results.
- return results;
- }
- }
- //return the null.
return null;
}
- public ItemStack getChemicalCombinationResult(IInventory par1IInventory){
- //Setting to flag.
- ((InventoryChemicalCombination) par1IInventory).setFlag(false);
-
- //variable of result.
- ItemStack result = null;
-
- //Just loop of amount of added recipe.
- for(int i = 0;i < ChemiCraftAPI.instance.getChemicalCombinationMaterial().size();i++){
-
- //Recipe the match?
- boolean match = true;
- //materialID & recipeID
- ArrayList<Integer> materialID = new ArrayList<Integer>();
- ArrayList<Integer> materialDamage = new ArrayList<Integer>();
- ArrayList<Integer> recipeID = new ArrayList<Integer>();
- ArrayList<Integer> recipeDamage = new ArrayList<Integer>();
-
- //Just loop of recipe size of recipe index i.
- for(int j = 0;j < ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i).length;j++){
- //Adding the recipe ID & Damage.
- recipeID.add(ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i)[j].itemID);
- recipeDamage.add(ChemiCraftAPI.instance.getChemicalCombinationMaterial().get(i)[j].getItemDamage());
- }
- //Just loop of 16.
- for(int j = 0;j < 16;j++){
- //Null check
- if(par1IInventory.getStackInSlot(j) != null){
- //Adding the materialID & Damage.
- materialID.add(par1IInventory.getStackInSlot(j).itemID);
- materialDamage.add(par1IInventory.getStackInSlot(j).getItemDamage());
+ public ItemStack getChemicalCombinationResult(ArrayList<String> atomsList, ArrayList<Integer> atomsAmountList){
+ ChemiCraftAPI api = ChemiCraftAPI.getInstance();
+ recipeSize :
+ for (int i = 0; i < api.getChemicalCombinationAtoms().size(); i++) {
+ FormulaPart[] var1 = new FormulaPart[atomsList.size()];
+ FormulaPart[] var2 = new FormulaPart[api.getChemicalCombinationAtoms().get(i).length];
+ for (int j = 0; j < atomsList.size(); j++) {
+ var1[j] = new FormulaPart(atomsList.get(j), atomsAmountList.get(j));
}
+ for (int j = 0; j < api.getChemicalCombinationAtoms().get(i).length; j++) {
+ var2[j] = new FormulaPart(api.getChemicalCombinationAtoms().get(i)[j], api.getChemicalCombinationAmounts().get(i)[j]);
+ }
+ Arrays.sort(var1, new ComparatorFormulaPart());
+ Arrays.sort(var2, new ComparatorFormulaPart());
+ if (var1.length != var2.length) {
+ continue recipeSize;
+ }
+ for (int j = 0; j < var1.length; j++) {
+ if (!var1[j].equals(var2[j])) {
+ continue recipeSize;
+ }
+ }
+ return api.getChemicalCombinationResult().get(i);
}
-
- //trimToSize & sorting.
- materialID.trimToSize();
- materialDamage.trimToSize();
- recipeID.trimToSize();
- recipeDamage.trimToSize();
- Collections.sort(materialID);
- Collections.sort(materialDamage);
- Collections.sort(recipeID);
- Collections.sort(recipeDamage);
-
- //Size check.
- if(materialID.size() != recipeID.size()){ match = false;}
- //Just loop of materialID.size().
- for(int j = 0;j < materialID.size();j++){
- //ID check.
- if(materialID.get(j) != recipeID.get(j)){ match = false;}
- //Damage check.
- if(materialDamage.get(j) != recipeDamage.get(j)){ match = false;}
- }
-
- //if "match == true"
- if(match){
- //Assignment to the result.
- result =
- new ItemStack(
- ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).itemID,
- ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).stackSize,
- ChemiCraftAPI.instance.getChemicalCombinationResult().get(i).getItemDamage()
- );
- //return the result.
- return result;
- }
- }
- //return the null.
return null;
}
- public void chemicalCrafting(InventoryChemicalCraftingMaterial par1IInventory, InventoryChemicalCraftingResult par2IInventory, InventoryChemicalCraftingNBT par3IInventory){
- ChemiCraftAPI api = ChemiCraftAPI.instance;
- int[] materialID = new int[par1IInventory.getSizeInventory()];
- int[] materialDamage = new int[par1IInventory.getSizeInventory()];
- int[] resultID = new int[par2IInventory.getSizeInventory()];
- int[] resultDamage = new int[par2IInventory.getSizeInventory()];
- int[] nbtID = new int[par3IInventory.getSizeInventory()];
- int[] nbtDamage = new int[par3IInventory.getSizeInventory()];
- //ItemID,ItemDamageの格納
- for(int j = 0;j < par1IInventory.getSizeInventory();j++){
- if(par1IInventory.getStackInSlot(j) != null){
- materialID[j] = par1IInventory.getStackInSlot(j).itemID;
- materialDamage[j] = par1IInventory.getStackInSlot(j).getItemDamage();
- }
- }
- for(int j = 0;j < par2IInventory.getSizeInventory();j++){
- if(par2IInventory.getStackInSlot(j) != null){
- resultID[j] = par2IInventory.getStackInSlot(j).itemID;
- resultDamage[j] = par2IInventory.getStackInSlot(j).getItemDamage();
- }
- }
- for(int j = 0;j < par3IInventory.getSizeInventory();j++){
- if(par3IInventory.getStackInSlot(j) != null){
- nbtID[j] = par3IInventory.getStackInSlot(j).itemID;
- nbtDamage[j] = par3IInventory.getStackInSlot(j).getItemDamage();
- }
- }
-
+ public ChemicalNBTRecipe chemicalCrafting(InventoryChemicalCraftingMaterial par1IInventory, InventoryChemicalCraftingResult par2IInventory, InventoryChemicalCraftingNBT par3IInventory){
+ ChemiCraftAPI api = ChemiCraftAPI.getInstance();
+ ChemicalNBTRecipe returnObj = null;
for(int i = 0;i < api.getMaterialRecipe().size();i++){
- api.getMaterialRecipe().get(i).match(par1IInventory);
+ ItemStack result = api.getMaterialRecipe().get(i).match(par1IInventory);
+ ItemStack resultArg = null;
+ if(result != null){
+ resultArg = new ItemStack(result.itemID, result.stackSize, result.getItemDamage());
+ if(api.getMaterialRecipe().get(i).nbtMatch(par1IInventory) != null){
+ ItemStack[] nbtInv = new ItemStack[par3IInventory.getSizeInventory()];
+ for(int j = 0;j < par3IInventory.getSizeInventory();j++){
+ nbtInv[j] = par3IInventory.getStackInSlot(j);
+ }
+ api.getMaterialRecipe().get(i).nbtMatch(par1IInventory).setNBT(nbtInv, resultArg);
+ }
+ returnObj = api.getMaterialRecipe().get(i).nbtMatch(par1IInventory);
+ }
+ par2IInventory.setInventorySlotContents(0, resultArg);
}
- return;
+ return returnObj;
}
private void clearResults(IInventory par1IInventory, int par2){
+ /*
+ * Commented by mozipi.
((InventoryDecomposition)par1IInventory).setFlag(false);
+ */
for(int i = 0;i < par2;i++){
par1IInventory.setInventorySlotContents(i, null);
}