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.inventory.InventoryChemicalCraftingMaterial;
8 import pcc.chemicraft.core.nbt.ChemicalNBTRecipe;
9 import pcc.chemicraft.util.Auxiliary.ArrayAuxiliary;
15 public class MaterialRecipe {
17 private ChemicalNBTRecipe nbtRecipe;
18 private ItemStack result;
19 private ItemStack[] material;
20 private boolean isSharpless = true;
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;
30 * インベントリの中にあるアイテムとレシピの内容が一致するかどうか判定します。<br>
31 * @param par1IInventory Inventory
32 * @return 一致したばあいはthis.resultを。それ以外はnull
34 @SuppressWarnings("unchecked")
35 public ItemStack match(InventoryChemicalCraftingMaterial par1IInventory){
36 ArrayList<ItemStack> invItemsArray = new ArrayList<ItemStack>();
38 for (int i = 0;i < par1IInventory.getSizeInventory();i++) {
39 invItemsArray.add(par1IInventory.getStackInSlot(i));
41 invItems = invItemsArray.toArray(new ItemStack[invItemsArray.size()]);
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;
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;
69 * @param par1IInventory Inventory
70 * @return 一致したらthis.nbt。それ以外はnull
72 @SuppressWarnings("unchecked")
73 public ChemicalNBTRecipe nbtMatch(InventoryChemicalCraftingMaterial par1IInventory){
74 ArrayList<ItemStack> invItemsArray = new ArrayList<ItemStack>();
76 for (int i = 0;i < par1IInventory.getSizeInventory();i++) {
77 invItemsArray.add(par1IInventory.getStackInSlot(i));
79 invItems = invItemsArray.toArray(new ItemStack[invItemsArray.size()]);
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;
90 return this.nbtRecipe;
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;
101 return this.nbtRecipe;