OSDN Git Service

I with OWATA
[chemicraft/chemicraft.git] / common / pcc / chemicraft / util / MaterialRecipe.java
1 package pcc.chemicraft.util;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5
6 import net.minecraft.item.ItemStack;
7 import pcc.chemicraft.core.ChemiCraftCore;
8 import pcc.chemicraft.core.inventory.InventoryChemicalCraftingMaterial;
9 import pcc.chemicraft.util.Auxiliary.ArrayAuxiliary;
10
11 public class MaterialRecipe {
12
13         private ChemicalNBTRecipe nbtRecipe;
14         private ItemStack result;
15         private ItemStack[] material;
16         private boolean isSharpless = true;
17
18         public MaterialRecipe(ItemStack par1ItemStack, ItemStack[] par2ItemStacks, ChemicalNBTRecipe par3NBTRecipe, boolean par4){
19                 this.result = par1ItemStack;
20                 this.material = par2ItemStacks.clone();
21                 this.nbtRecipe = par3NBTRecipe;
22                 this.isSharpless = par4;
23         }
24
25         @SuppressWarnings("unchecked")
26         public ItemStack match(InventoryChemicalCraftingMaterial par1IInventory){
27                 ArrayList<ItemStack> invItemsArray = new ArrayList<ItemStack>();
28                 ItemStack[] invItems;
29                 for(int i = 0;i < par1IInventory.getSizeInventory();i++){
30                         invItemsArray.add(par1IInventory.getStackInSlot(i));
31                 }
32                 invItems = invItemsArray.toArray(new ItemStack[invItemsArray.size()]);
33
34                 if(isSharpless){
35                         Arrays.sort(invItems, new ComparatorItemStack());
36                         Arrays.sort(this.material, new ComparatorItemStack());
37                         invItems = (ItemStack[]) ArrayAuxiliary.deleteNull(invItems);
38                         if(invItems.length != this.material.length) return null;
39                         for(int i = 0;i < this.material.length;i++){
40                                 if(this.material[i].itemID != invItems[i].itemID) return null;
41                                 if(this.material[i].getItemDamage() != invItems[i].getItemDamage()) return null;
42                         }
43                         return this.result;
44                 }else{
45                         if(this.material.length != invItems.length) return null;
46                         for(int i = 0;i < this.material.length;i++){
47                                 if(this.material[i] == null && invItems[i] != null) return null;
48                                 if(this.material[i] != null && invItems[i] == null) return null;
49                                 if(this.material[i] != null && invItems[i] != null){
50                                         if(this.material[i].itemID != invItems[i].itemID) return null;
51                                         if(this.material[i].getItemDamage() != invItems[i].getItemDamage()) return null;
52                                 }
53                         }
54                         return this.result;
55                 }
56         }
57
58         @SuppressWarnings("unchecked")
59         public ChemicalNBTRecipe nbtMatch(InventoryChemicalCraftingMaterial par1IInventory){
60                 ArrayList<ItemStack> invItemsArray = new ArrayList<ItemStack>();
61                 ItemStack[] invItems;
62                 for(int i = 0;i < par1IInventory.getSizeInventory();i++){
63                         invItemsArray.add(par1IInventory.getStackInSlot(i));
64                 }
65                 invItems = invItemsArray.toArray(new ItemStack[invItemsArray.size()]);
66
67                 if(isSharpless){
68                         Arrays.sort(invItems, new ComparatorItemStack());
69                         Arrays.sort(this.material, new ComparatorItemStack());
70                         invItems = (ItemStack[]) ArrayAuxiliary.deleteNull(invItems);
71                         if(invItems.length != this.material.length) return null;
72                         for(int i = 0;i < this.material.length;i++){
73                                 if(this.material[i].itemID != invItems[i].itemID) return null;
74                                 if(this.material[i].getItemDamage() != invItems[i].getItemDamage()) return null;
75                         }
76                         System.out.println(this.nbtRecipe);
77                         return this.nbtRecipe;
78                 }else{
79                         if(this.material.length != invItems.length) return null;
80                         for(int i = 0;i < this.material.length;i++){
81                                 if(this.material[i] == null && invItems[i] != null) return null;
82                                 if(this.material[i] != null && invItems[i] == null) return null;
83                                 if(this.material[i] != null && invItems[i] != null){
84                                         if(this.material[i].itemID != invItems[i].itemID) return null;
85                                         if(this.material[i].getItemDamage() != invItems[i].getItemDamage()) return null;
86                                 }
87                         }
88                         return this.nbtRecipe;
89                 }
90         }
91
92 }