001package net.minecraft.item.crafting; 002 003import java.util.ArrayList; 004import java.util.Iterator; 005import java.util.List; 006import net.minecraft.inventory.InventoryCrafting; 007import net.minecraft.item.ItemStack; 008import net.minecraft.world.World; 009 010public class ShapelessRecipes implements IRecipe 011{ 012 /** Is the ItemStack that you get when craft the recipe. */ 013 private final ItemStack recipeOutput; 014 015 /** Is a List of ItemStack that composes the recipe. */ 016 public final List recipeItems; 017 018 public ShapelessRecipes(ItemStack par1ItemStack, List par2List) 019 { 020 this.recipeOutput = par1ItemStack; 021 this.recipeItems = par2List; 022 } 023 024 public ItemStack getRecipeOutput() 025 { 026 return this.recipeOutput; 027 } 028 029 /** 030 * Used to check if a recipe matches current crafting inventory 031 */ 032 public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World) 033 { 034 ArrayList arraylist = new ArrayList(this.recipeItems); 035 036 for (int i = 0; i < 3; ++i) 037 { 038 for (int j = 0; j < 3; ++j) 039 { 040 ItemStack itemstack = par1InventoryCrafting.getStackInRowAndColumn(j, i); 041 042 if (itemstack != null) 043 { 044 boolean flag = false; 045 Iterator iterator = arraylist.iterator(); 046 047 while (iterator.hasNext()) 048 { 049 ItemStack itemstack1 = (ItemStack)iterator.next(); 050 051 if (itemstack.itemID == itemstack1.itemID && (itemstack1.getItemDamage() == 32767 || itemstack.getItemDamage() == itemstack1.getItemDamage())) 052 { 053 flag = true; 054 arraylist.remove(itemstack1); 055 break; 056 } 057 } 058 059 if (!flag) 060 { 061 return false; 062 } 063 } 064 } 065 } 066 067 return arraylist.isEmpty(); 068 } 069 070 /** 071 * Returns an Item that is the result of this recipe 072 */ 073 public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting) 074 { 075 return this.recipeOutput.copy(); 076 } 077 078 /** 079 * Returns the size of the recipe area 080 */ 081 public int getRecipeSize() 082 { 083 return this.recipeItems.size(); 084 } 085}