    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.netherrack.blockID, new ItemStack(Item.netherrackBrick), 0.1F);
    046        this.addSmelting(Block.oreCoal.blockID, new ItemStack(Item.coal), 0.1F);
    047        this.addSmelting(Block.oreRedstone.blockID, new ItemStack(Item.redstone), 0.7F);
    048        this.addSmelting(Block.oreLapis.blockID, new ItemStack(Item.dyePowder, 1, 4), 0.2F);
    049        this.addSmelting(Block.oreNetherQuartz.blockID, new ItemStack(Item.netherQuartz), 0.2F);
    050    }
    051
    052    /**
    053     * Adds a smelting recipe.
    054     */
    055    public void addSmelting(int par1, ItemStack par2ItemStack, float par3)
    056    {
    057        this.smeltingList.put(Integer.valueOf(par1), par2ItemStack);
    058        this.experienceList.put(Integer.valueOf(par2ItemStack.itemID), Float.valueOf(par3));
    059    }
    060
    061    /**
    062     * Returns the smelting result of an item.
    063     * Deprecated in favor of a metadata sensitive version
    064     */
    065    @Deprecated
    066    public ItemStack getSmeltingResult(int par1)
    067    {
    068        return (ItemStack)this.smeltingList.get(Integer.valueOf(par1));
    069    }
    070
    071    public Map getSmeltingList()
    072    {
    073        return this.smeltingList;
    074    }
    075
    076    @Deprecated //In favor of ItemStack sensitive version
    077    public float getExperience(int par1)
    078    {
    079        return this.experienceList.containsKey(Integer.valueOf(par1)) ? ((Float)this.experienceList.get(Integer.valueOf(par1))).floatValue() : 0.0F;
    080    }
    081
    082    /**
    083     * A metadata sensitive version of adding a furnace recipe.
    084     */
    085    public void addSmelting(int itemID, int metadata, ItemStack itemstack, float experience)
    086    {
    087        metaSmeltingList.put(Arrays.asList(itemID, metadata), itemstack);
    088        metaExperience.put(Arrays.asList(itemID, metadata), experience);
    089    }
    090
    091    /**
    092     * Used to get the resulting ItemStack form a source ItemStack
    093     * @param item The Source ItemStack
    094     * @return The result ItemStack
    095     */
    096    public ItemStack getSmeltingResult(ItemStack item)
    097    {
    098        if (item == null)
    099        {
    100            return null;
    101        }
    102        ItemStack ret = (ItemStack)metaSmeltingList.get(Arrays.asList(item.itemID, item.getItemDamage()));
    103        if (ret != null)
    104        {
    105            return ret;
    106        }
    107        return (ItemStack)smeltingList.get(Integer.valueOf(item.itemID));
    108    }
    109
    110    /**
    111     * Grabs the amount of base experience for this item to give when pulled from the furnace slot.
    112     */
    113    public float getExperience(ItemStack item)
    114    {
    115        if (item == null || item.getItem() == null)
    116        {
    117            return 0;
    118        }
    119        float ret = item.getItem().getSmeltingExperience(item);
    120        if (ret < 0 && metaExperience.containsKey(Arrays.asList(item.itemID, item.getItemDamage())))
    121        {
    122            ret = metaExperience.get(Arrays.asList(item.itemID, item.getItemDamage()));
    123        }
    124        if (ret < 0 && experienceList.containsKey(item.itemID))
    125        {
    126            ret = ((Float)experienceList.get(item.itemID)).floatValue();
    127        }
    128        return (ret < 0 ? 0 : ret);
    129    }
    130
    131    public Map<List<Integer>, ItemStack> getMetaSmeltingList()
    132    {
    133        return metaSmeltingList;
    134    }
    135}