OSDN Git Service

d1c3ba450d528700237c881539a31e6d4ef04d76
[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.inventory.InventoryChemicalCraftingMaterial;
8 import pcc.chemicraft.core.nbt.ChemicalNBTRecipe;
9 import pcc.chemicraft.util.Auxiliary.ArrayAuxiliary;
10
11 /**
12  * 素材制作台のレシピを格納するクラスです
13  * @author mozipi
14  */
15 public class MaterialRecipe {
16
17         private ChemicalNBTRecipe nbtRecipe;
18         private ItemStack result;
19         private ItemStack[] material;
20         private boolean isSharpless = true;
21
22         public MaterialRecipe(ItemStack par1ItemStack, ItemStack[] par2ItemStacks, ChemicalNBTRecipe par3NBTRecipe, boolean par4){
23                 this.result = par1ItemStack;
24                 this.material = par2ItemStacks.clone();
25                 this.nbtRecipe = par3NBTRecipe;
26                 this.isSharpless = par4;
27         }
28
29         /**
30          * インベントリの中にあるアイテムとレシピの内容が一致するかどうか判定します。<br>
31          * @param par1IInventory Inventory
32          * @return 一致したばあいはthis.resultを。それ以外はnull
33          */
34         @SuppressWarnings("unchecked")
35         public ItemStack match(InventoryChemicalCraftingMaterial par1IInventory){
36                 ArrayList<ItemStack> invItemsArray = new ArrayList<ItemStack>();
37                 ItemStack[] invItems;
38                 for (int i = 0;i < par1IInventory.getSizeInventory();i++) {
39                         invItemsArray.add(par1IInventory.getStackInSlot(i));
40                 }
41                 invItems = invItemsArray.toArray(new ItemStack[invItemsArray.size()]);
42
43                 if (isSharpless) {
44                         Arrays.sort(invItems, new ComparatorItemStack());
45                         Arrays.sort(this.material, new ComparatorItemStack());
46                         invItems = (ItemStack[]) ArrayAuxiliary.deleteNull(invItems);
47                         if (invItems.length != this.material.length) return null;
48                         for (int i = 0;i < this.material.length;i++) {
49                                 if (this.material[i].itemID != invItems[i].itemID) return null;
50                                 if (this.material[i].getItemDamage() != invItems[i].getItemDamage()) return null;
51                         }
52                         return this.result;
53                 } else {
54                         if (this.material.length != invItems.length) return null;
55                         for (int i = 0;i < this.material.length;i++) {
56                                 if (this.material[i] == null && invItems[i] != null) return null;
57                                 if (this.material[i] != null && invItems[i] == null) return null;
58                                 if (this.material[i] != null && invItems[i] != null){
59                                         if (this.material[i].itemID != invItems[i].itemID) return null;
60                                         if (this.material[i].getItemDamage() != invItems[i].getItemDamage()) return null;
61                                 }
62                         }
63                         return this.result;
64                 }
65         }
66
67         /**
68          * NBTが一致するかどうか判定します
69          * @param par1IInventory Inventory
70          * @return 一致したらthis.nbt。それ以外はnull
71          */
72         @SuppressWarnings("unchecked")
73         public ChemicalNBTRecipe nbtMatch(InventoryChemicalCraftingMaterial par1IInventory){
74                 ArrayList<ItemStack> invItemsArray = new ArrayList<ItemStack>();
75                 ItemStack[] invItems;
76                 for (int i = 0;i < par1IInventory.getSizeInventory();i++) {
77                         invItemsArray.add(par1IInventory.getStackInSlot(i));
78                 }
79                 invItems = invItemsArray.toArray(new ItemStack[invItemsArray.size()]);
80
81                 if (isSharpless) {
82                         Arrays.sort(invItems, new ComparatorItemStack());
83                         Arrays.sort(this.material, new ComparatorItemStack());
84                         invItems = (ItemStack[]) ArrayAuxiliary.deleteNull(invItems);
85                         if (invItems.length != this.material.length) return null;
86                         for (int i = 0;i < this.material.length;i++) {
87                                 if (this.material[i].itemID != invItems[i].itemID) return null;
88                                 if (this.material[i].getItemDamage() != invItems[i].getItemDamage()) return null;
89                         }
90                         return this.nbtRecipe;
91                 }else{
92                         if (this.material.length != invItems.length) return null;
93                         for (int i = 0;i < this.material.length;i++) {
94                                 if (this.material[i] == null && invItems[i] != null) return null;
95                                 if (this.material[i] != null && invItems[i] == null) return null;
96                                 if (this.material[i] != null && invItems[i] != null) {
97                                         if (this.material[i].itemID != invItems[i].itemID) return null;
98                                         if (this.material[i].getItemDamage() != invItems[i].getItemDamage()) return null;
99                                 }
100                         }
101                         return this.nbtRecipe;
102                 }
103         }
104
105 }