OSDN Git Service

素材製作台(減算処理・NBT処理抜き)を製作
[chemicraft/chemicraft.git] / common / chemicraft / util / MaterialRecipe.java
index 276f92d..6d26e7d 100644 (file)
@@ -1,9 +1,7 @@
 package chemicraft.util;
 
-import java.lang.reflect.Array;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
 
 import net.minecraft.src.ItemStack;
 import chemicraft.ChemiCraft;
@@ -34,16 +32,56 @@ public class MaterialRecipe {
                invItems = (ItemStack[]) ChemiCraft.instance.arrayAuxiliary.deleteNull(invItems);
 
                if(isSharpless){
-                       Arrays.sort(invItems, new ComparaterItemStackID());
-
+                       Arrays.sort(invItems, new ComparatorItemStack());
+                       Arrays.sort(this.material, new ComparatorItemStack());
+                       if(invItems.length != this.material.length) return null;
+                       for(int i = 0;i < this.material.length;i++){
+                               if(this.material[i].itemID != invItems[i].itemID) return null;
+                               if(this.material[i].getItemDamage() != invItems[i].getItemDamage()) return null;
+                       }
+                       return this.result;
                }else{
-
+                       if(this.material.length != invItems.length) return null;
+                       for(int i = 0;i < this.material.length;i++){
+                               if(this.material[i] == null && invItems[i] != null) return null;
+                               if(this.material[i] != null && invItems[i] == null) return null;
+                               if(this.material[i] != null && invItems[i] != null){
+                                       if(this.material[i].itemID != invItems[i].itemID) return null;
+                                       if(this.material[i].getItemDamage() != invItems[i].getItemDamage()) return null;
+                               }
+                       }
+                       return this.result;
                }
-               return null;
        }
 
-       public ItemStack[] nbtMatch(InventoryChemicalCraftingNBT par1IInventory){
-               return null;
+       public ChemicalNBTRecipe nbtMatch(InventoryChemicalCraftingMaterial par1IInventory){
+               ArrayList<ItemStack> invItemsArray = new ArrayList<ItemStack>();
+               ItemStack[] invItems;
+               for(int i = 0;i < par1IInventory.getSizeInventory();i++){
+                       invItemsArray.add(par1IInventory.getStackInSlot(i));
+               }
+               invItems = invItemsArray.toArray(new ItemStack[invItemsArray.size()]);
+               invItems = (ItemStack[]) ChemiCraft.instance.arrayAuxiliary.deleteNull(invItems);
+
+               if(isSharpless){
+                       Arrays.sort(invItems, new ComparatorItemStack());
+                       Arrays.sort(this.material, new ComparatorItemStack());
+                       if(invItems.length != this.material.length) return null;
+                       for(int i = 0;i < this.material.length;i++){
+                               if(this.material[i].itemID != invItems[i].itemID) return null;
+                               if(this.material[i].getItemDamage() != invItems[i].getItemDamage()) return null;
+                       }
+                       return this.nbtRecipe;
+               }else{
+                       if(this.material.length != invItems.length) return null;
+                       for(int i = 0;i < this.material.length;i++){
+                               if(this.material[i] != null && invItems[i] != null){
+                                       if(this.material[i].itemID != invItems[i].itemID) return null;
+                                       if(this.material[i].getItemDamage() != invItems[i].getItemDamage()) return null;
+                               }
+                       }
+                       return this.nbtRecipe;
+               }
        }
 
 }