    001package net.minecraft.item.crafting;
    002
    003import java.util.Arrays;
    004import java.util.HashMap;
    005import java.util.List;
    006import java.util.Map;
    007import net.minecraft.block.Block;
    008import net.minecraft.item.Item;
    009import net.minecraft.item.ItemStack;
    010
    011public 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.itemID, new ItemStack(Item.porkCooked), 0.35F);
    036        this.addSmelting(Item.beefRaw.itemID, new ItemStack(Item.beefCooked), 0.35F);
    037        this.addSmelting(Item.chickenRaw.itemID, new ItemStack(Item.chickenCooked), 0.35F);
    038        this.addSmelting(Item.fishRaw.itemID, new ItemStack(Item.fishCooked), 0.35F);
    039        this.addSmelting(Block.cobblestone.blockID, new ItemStack(Block.stone), 0.1F);
    040        this.addSmelting(Item.clay.itemID, 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.itemID, 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     * A metadata sensitive version of adding a furnace recipe.
    082     */
    083    public void addSmelting(int itemID, int metadata, ItemStack itemstack, float experience)
    084    {
    085        metaSmeltingList.put(Arrays.asList(itemID, metadata), itemstack);
    086        metaExperience.put(Arrays.asList(itemID, metadata), experience);
    087    }
    088
    089    /**
    090     * Used to get the resulting ItemStack form a source ItemStack
    091     * @param item The Source ItemStack
    092     * @return The result ItemStack
    093     */
    094    public ItemStack getSmeltingResult(ItemStack item)
    095    {
    096        if (item == null)
    097        {
    098            return null;
    099        }
    100        ItemStack ret = (ItemStack)metaSmeltingList.get(Arrays.asList(item.itemID, item.getItemDamage()));
    101        if (ret != null)
    102        {
    103            return ret;
    104        }
    105        return (ItemStack)smeltingList.get(Integer.valueOf(item.itemID));
    106    }
    107
    108    /**
    109     * Grabs the amount of base experience for this item to give when pulled from the furnace slot.
    110     */
    111    public float getExperience(ItemStack item)
    112    {
    113        if (item == null || item.getItem() == null)
    114        {
    115            return 0;
    116        }
    117        float ret = item.getItem().getSmeltingExperience(item);
    118        if (ret < 0 && metaExperience.containsKey(Arrays.asList(item.itemID, item.getItemDamage())))
    119        {
    120            ret = metaExperience.get(Arrays.asList(item.itemID, item.getItemDamage()));
    121        }
    122        if (ret < 0 && experienceList.containsKey(item.itemID))
    123        {
    124            ret = ((Float)experienceList.get(item.itemID)).floatValue();
    125        }
    126        return (ret < 0 ? 0 : ret);
    127    }
    128
    129    public Map<List<Integer>, ItemStack> getMetaSmeltingList()
    130    {
    131        return metaSmeltingList;
    132    }
    133}