    001    package net.minecraft.src;
    002
    003    import java.util.Arrays;
    004    import java.util.HashMap;
    005    import java.util.List;
    006    import java.util.Map;
    007
    008    public class FurnaceRecipes
    009    {
    010        private static final FurnaceRecipes smeltingBase = new FurnaceRecipes();
    011
    012        /** The list of smelting results. */
    013        private Map smeltingList = new HashMap();
    014        private Map experienceList = new HashMap();
    015        private HashMap<List<Integer>, ItemStack> metaSmeltingList = new HashMap<List<Integer>, ItemStack>();
    016        private HashMap<List<Integer>, Float> metaExperience = new HashMap<List<Integer>, Float>();
    017
    018        /**
    019         * Used to call methods addSmelting and getSmeltingResult.
    020         */
    021        public static final FurnaceRecipes smelting()
    022        {
    023            return smeltingBase;
    024        }
    025
    026        private FurnaceRecipes()
    027        {
    028            this.addSmelting(Block.oreIron.blockID, new ItemStack(Item.ingotIron), 0.7F);
    029            this.addSmelting(Block.oreGold.blockID, new ItemStack(Item.ingotGold), 1.0F);
    030            this.addSmelting(Block.oreDiamond.blockID, new ItemStack(Item.diamond), 1.0F);
    031            this.addSmelting(Block.sand.blockID, new ItemStack(Block.glass), 0.1F);
    032            this.addSmelting(Item.porkRaw.shiftedIndex, new ItemStack(Item.porkCooked), 0.35F);
    033            this.addSmelting(Item.beefRaw.shiftedIndex, new ItemStack(Item.beefCooked), 0.35F);
    034            this.addSmelting(Item.chickenRaw.shiftedIndex, new ItemStack(Item.chickenCooked), 0.35F);
    035            this.addSmelting(Item.fishRaw.shiftedIndex, new ItemStack(Item.fishCooked), 0.35F);
    036            this.addSmelting(Block.cobblestone.blockID, new ItemStack(Block.stone), 0.1F);
    037            this.addSmelting(Item.clay.shiftedIndex, new ItemStack(Item.brick), 0.3F);
    038            this.addSmelting(Block.cactus.blockID, new ItemStack(Item.dyePowder, 1, 2), 0.2F);
    039            this.addSmelting(Block.wood.blockID, new ItemStack(Item.coal, 1, 1), 0.15F);
    040            this.addSmelting(Block.oreEmerald.blockID, new ItemStack(Item.emerald), 1.0F);
    041            this.addSmelting(Item.potatoe.shiftedIndex, new ItemStack(Item.bakedPotato), 0.35F);
    042            this.addSmelting(Block.oreCoal.blockID, new ItemStack(Item.coal), 0.1F);
    043            this.addSmelting(Block.oreRedstone.blockID, new ItemStack(Item.redstone), 0.7F);
    044            this.addSmelting(Block.oreLapis.blockID, new ItemStack(Item.dyePowder, 1, 4), 0.2F);
    045        }
    046
    047        /**
    048         * Adds a smelting recipe.
    049         */
    050        public void addSmelting(int par1, ItemStack par2ItemStack, float par3)
    051        {
    052            this.smeltingList.put(Integer.valueOf(par1), par2ItemStack);
    053            this.experienceList.put(Integer.valueOf(par2ItemStack.itemID), Float.valueOf(par3));
    054        }
    055
    056        /**
    057         * Returns the smelting result of an item.
    058         * Deprecated in favor of a metadata sensitive version
    059         */
    060        @Deprecated
    061        public ItemStack getSmeltingResult(int par1)
    062        {
    063            return (ItemStack)this.smeltingList.get(Integer.valueOf(par1));
    064        }
    065
    066        public Map getSmeltingList()
    067        {
    068            return this.smeltingList;
    069        }
    070
    071        @Deprecated //In favor of ItemStack sensitive version
    072        public float getExperience(int par1)
    073        {
    074            return this.experienceList.containsKey(Integer.valueOf(par1)) ? ((Float)this.experienceList.get(Integer.valueOf(par1))).floatValue() : 0.0F;
    075        }
    076
    077        /**
    078         * Add a metadata-sensitive furnace recipe
    079         * @param itemID The Item ID
    080         * @param metadata The Item Metadata
    081         * @param itemstack The ItemStack for the result
    082         */
    083        @Deprecated //In favor of the exp version, will remove next major MC version.
    084        public void addSmelting(int itemID, int metadata, ItemStack itemstack)
    085        {
    086            addSmelting(itemID, metadata, itemstack, 0.0f);
    087        }
    088
    089        /**
    090         * A metadata sensitive version of adding a furnace recipe.
    091         */
    092        public void addSmelting(int itemID, int metadata, ItemStack itemstack, float experience)
    093        {
    094            metaSmeltingList.put(Arrays.asList(itemID, metadata), itemstack);
    095            metaExperience.put(Arrays.asList(itemID, metadata), experience);
    096        }
    097
    098        /**
    099         * Used to get the resulting ItemStack form a source ItemStack
    100         * @param item The Source ItemStack
    101         * @return The result ItemStack
    102         */
    103        public ItemStack getSmeltingResult(ItemStack item)
    104        {
    105            if (item == null)
    106            {
    107                return null;
    108            }
    109            ItemStack ret = (ItemStack)metaSmeltingList.get(Arrays.asList(item.itemID, item.getItemDamage()));
    110            if (ret != null)
    111            {
    112                return ret;
    113            }
    114            return (ItemStack)smeltingList.get(Integer.valueOf(item.itemID));
    115        }
    116
    117        /**
    118         * Grabs the amount of base experience for this item to give when pulled from the furnace slot.
    119         */
    120        public float getExperience(ItemStack item)
    121        {
    122            if (item == null || item.getItem() == null)
    123            {
    124                return 0;
    125            }
    126            float ret = item.getItem().getSmeltingExperience(item);
    127            if (ret < 0 && metaExperience.containsKey(Arrays.asList(item.itemID, item.getItemDamage())))
    128            {
    129                ret = metaExperience.get(Arrays.asList(item.itemID, item.getItemDamage()));
    130            }
    131            if (ret < 0 && experienceList.containsKey(item.itemID))
    132            {
    133                ret = ((Float)experienceList.get(item.itemID)).floatValue();
    134            }
    135            return (ret < 0 ? 0 : ret);
    136        }
    137    }