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