OSDN Git Service

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