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