    001    package net.minecraft.src;
    002
    003    import java.util.ArrayList;
    004
    005    public class RecipesArmorDyes implements IRecipe
    006    {
    007        /**
    008         * Used to check if a recipe matches current crafting inventory
    009         */
    010        public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
    011        {
    012            ItemStack var3 = null;
    013            ArrayList var4 = new ArrayList();
    014
    015            for (int var5 = 0; var5 < par1InventoryCrafting.getSizeInventory(); ++var5)
    016            {
    017                ItemStack var6 = par1InventoryCrafting.getStackInSlot(var5);
    018
    019                if (var6 != null)
    020                {
    021                    if (var6.getItem() instanceof ItemArmor)
    022                    {
    023                        ItemArmor var7 = (ItemArmor)var6.getItem();
    024
    025                        if (var7.func_82812_d() != EnumArmorMaterial.CLOTH || var3 != null)
    026                        {
    027                            return false;
    028                        }
    029
    030                        var3 = var6;
    031                    }
    032                    else
    033                    {
    034                        if (var6.itemID != Item.dyePowder.shiftedIndex)
    035                        {
    036                            return false;
    037                        }
    038
    039                        var4.add(var6);
    040                    }
    041                }
    042            }
    043
    044            return var3 != null && !var4.isEmpty();
    045        }
    046
    047        /**
    048         * Returns an Item that is the result of this recipe
    049         */
    050        public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
    051        {
    052            ItemStack var2 = null;
    053            int[] var3 = new int[3];
    054            int var4 = 0;
    055            int var5 = 0;
    056            ItemArmor var6 = null;
    057            int var7;
    058            int var9;
    059            float var10;
    060            float var11;
    061            int var17;
    062
    063            for (var7 = 0; var7 < par1InventoryCrafting.getSizeInventory(); ++var7)
    064            {
    065                ItemStack var8 = par1InventoryCrafting.getStackInSlot(var7);
    066
    067                if (var8 != null)
    068                {
    069                    if (var8.getItem() instanceof ItemArmor)
    070                    {
    071                        var6 = (ItemArmor)var8.getItem();
    072
    073                        if (var6.func_82812_d() != EnumArmorMaterial.CLOTH || var2 != null)
    074                        {
    075                            return null;
    076                        }
    077
    078                        var2 = var8.copy();
    079
    080                        if (var6.func_82816_b_(var8))
    081                        {
    082                            var9 = var6.func_82814_b(var2);
    083                            var10 = (float)(var9 >> 16 & 255) / 255.0F;
    084                            var11 = (float)(var9 >> 8 & 255) / 255.0F;
    085                            float var12 = (float)(var9 & 255) / 255.0F;
    086                            var4 = (int)((float)var4 + Math.max(var10, Math.max(var11, var12)) * 255.0F);
    087                            var3[0] = (int)((float)var3[0] + var10 * 255.0F);
    088                            var3[1] = (int)((float)var3[1] + var11 * 255.0F);
    089                            var3[2] = (int)((float)var3[2] + var12 * 255.0F);
    090                            ++var5;
    091                        }
    092                    }
    093                    else
    094                    {
    095                        if (var8.itemID != Item.dyePowder.shiftedIndex)
    096                        {
    097                            return null;
    098                        }
    099
    100                        float[] var14 = EntitySheep.fleeceColorTable[BlockCloth.getBlockFromDye(var8.getItemDamage())];
    101                        int var16 = (int)(var14[0] * 255.0F);
    102                        int var15 = (int)(var14[1] * 255.0F);
    103                        var17 = (int)(var14[2] * 255.0F);
    104                        var4 += Math.max(var16, Math.max(var15, var17));
    105                        var3[0] += var16;
    106                        var3[1] += var15;
    107                        var3[2] += var17;
    108                        ++var5;
    109                    }
    110                }
    111            }
    112
    113            if (var6 == null)
    114            {
    115                return null;
    116            }
    117            else
    118            {
    119                var7 = var3[0] / var5;
    120                int var13 = var3[1] / var5;
    121                var9 = var3[2] / var5;
    122                var10 = (float)var4 / (float)var5;
    123                var11 = (float)Math.max(var7, Math.max(var13, var9));
    124                var7 = (int)((float)var7 * var10 / var11);
    125                var13 = (int)((float)var13 * var10 / var11);
    126                var9 = (int)((float)var9 * var10 / var11);
    127                var17 = (var7 << 8) + var13;
    128                var17 = (var17 << 8) + var9;
    129                var6.func_82813_b(var2, var17);
    130                return var2;
    131            }
    132        }
    133
    134        /**
    135         * Returns the size of the recipe area
    136         */
    137        public int getRecipeSize()
    138        {
    139            return 10;
    140        }
    141
    142        public ItemStack getRecipeOutput()
    143        {
    144            return null;
    145        }
    146    }