1 package pcc.chemicraft.util;
3 import java.util.ArrayList;
4 import java.util.Arrays;
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;
16 public class MaterialRecipe {
18 private ChemicalNBTRecipe nbtRecipe;
19 private ItemStack result;
20 private ItemStack[] material;
21 private boolean isSharpless = true;
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;
31 * インベントリの中にあるアイテムとレシピの内容が一致するかどうか判定します。<br>
32 * @param par1IInventory Inventory
33 * @return 一致したばあいはthis.resultを。それ以外はnull
35 @SuppressWarnings("unchecked")
36 public ItemStack match(InventoryChemicalCraftingMaterial par1IInventory){
37 ArrayList<ItemStack> invItemsArray = new ArrayList<ItemStack>();
39 for (int i = 0;i < par1IInventory.getSizeInventory();i++) {
40 invItemsArray.add(par1IInventory.getStackInSlot(i));
42 invItems = invItemsArray.toArray(new ItemStack[invItemsArray.size()]);
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;
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;
70 * @param par1IInventory Inventory
71 * @return 一致したらthis.nbt。それ以外はnull
73 @SuppressWarnings("unchecked")
74 public ChemicalNBTRecipe nbtMatch(InventoryChemicalCraftingMaterial par1IInventory){
75 ArrayList<ItemStack> invItemsArray = new ArrayList<ItemStack>();
77 for (int i = 0;i < par1IInventory.getSizeInventory();i++) {
78 invItemsArray.add(par1IInventory.getStackInSlot(i));
80 invItems = invItemsArray.toArray(new ItemStack[invItemsArray.size()]);
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;
91 return this.nbtRecipe;
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;
102 return this.nbtRecipe;