| 1 | package net.minecraft.item.crafting;
|
| 2 |
|
| 3 | import com.google.common.collect.Maps;
|
| 4 | import java.util.Map;
|
| 5 | import java.util.Map.Entry;
|
| 6 | import net.minecraft.block.Block;
|
| 7 | import net.minecraft.block.BlockStoneBrick;
|
| 8 | import net.minecraft.init.Blocks;
|
| 9 | import net.minecraft.init.Items;
|
| 10 | import net.minecraft.item.EnumDyeColor;
|
| 11 | import net.minecraft.item.Item;
|
| 12 | import net.minecraft.item.ItemFishFood;
|
| 13 | import net.minecraft.item.ItemStack;
|
| 14 |
|
| 15 | public class FurnaceRecipes
|
| 16 | {
|
| 17 | private static final FurnaceRecipes smeltingBase = new FurnaceRecipes();
|
| 18 | private Map<ItemStack, ItemStack> smeltingList = Maps.<ItemStack, ItemStack>newHashMap();
|
| 19 | private Map<ItemStack, Float> experienceList = Maps.<ItemStack, Float>newHashMap();
|
| 20 |
|
| 21 | /**
|
| 22 | * Returns an instance of FurnaceRecipes.
|
| 23 | */
|
| 24 | public static FurnaceRecipes instance()
|
| 25 | {
|
| 26 | return smeltingBase;
|
| 27 | }
|
| 28 |
|
| 29 | private FurnaceRecipes()
|
| 30 | {
|
| 31 | this.addSmeltingRecipeForBlock(Blocks.iron_ore, new ItemStack(Items.iron_ingot), 0.7F);
|
| 32 | this.addSmeltingRecipeForBlock(Blocks.gold_ore, new ItemStack(Items.gold_ingot), 1.0F);
|
| 33 | this.addSmeltingRecipeForBlock(Blocks.diamond_ore, new ItemStack(Items.diamond), 1.0F);
|
| 34 | this.addSmeltingRecipeForBlock(Blocks.sand, new ItemStack(Blocks.glass), 0.1F);
|
| 35 | this.addSmelting(Items.porkchop, new ItemStack(Items.cooked_porkchop), 0.35F);
|
| 36 | this.addSmelting(Items.beef, new ItemStack(Items.cooked_beef), 0.35F);
|
| 37 | this.addSmelting(Items.chicken, new ItemStack(Items.cooked_chicken), 0.35F);
|
| 38 | this.addSmelting(Items.rabbit, new ItemStack(Items.cooked_rabbit), 0.35F);
|
| 39 | this.addSmelting(Items.mutton, new ItemStack(Items.cooked_mutton), 0.35F);
|
| 40 | this.addSmeltingRecipeForBlock(Blocks.cobblestone, new ItemStack(Blocks.stone), 0.1F);
|
| 41 | this.addSmeltingRecipe(new ItemStack(Blocks.stonebrick, 1, BlockStoneBrick.DEFAULT_META), new ItemStack(Blocks.stonebrick, 1, BlockStoneBrick.CRACKED_META), 0.1F);
|
| 42 | this.addSmelting(Items.clay_ball, new ItemStack(Items.brick), 0.3F);
|
| 43 | this.addSmeltingRecipeForBlock(Blocks.clay, new ItemStack(Blocks.hardened_clay), 0.35F);
|
| 44 | this.addSmeltingRecipeForBlock(Blocks.cactus, new ItemStack(Items.dye, 1, EnumDyeColor.GREEN.getDyeDamage()), 0.2F);
|
| 45 | this.addSmeltingRecipeForBlock(Blocks.log, new ItemStack(Items.coal, 1, 1), 0.15F);
|
| 46 | this.addSmeltingRecipeForBlock(Blocks.log2, new ItemStack(Items.coal, 1, 1), 0.15F);
|
| 47 | this.addSmeltingRecipeForBlock(Blocks.emerald_ore, new ItemStack(Items.emerald), 1.0F);
|
| 48 | this.addSmelting(Items.potato, new ItemStack(Items.baked_potato), 0.35F);
|
| 49 | this.addSmeltingRecipeForBlock(Blocks.netherrack, new ItemStack(Items.netherbrick), 0.1F);
|
| 50 | this.addSmeltingRecipe(new ItemStack(Blocks.sponge, 1, 1), new ItemStack(Blocks.sponge, 1, 0), 0.15F);
|
| 51 |
|
| 52 | for (ItemFishFood.FishType itemfishfood$fishtype : ItemFishFood.FishType.values())
|
| 53 | {
|
| 54 | if (itemfishfood$fishtype.canCook())
|
| 55 | {
|
| 56 | this.addSmeltingRecipe(new ItemStack(Items.fish, 1, itemfishfood$fishtype.getMetadata()), new ItemStack(Items.cooked_fish, 1, itemfishfood$fishtype.getMetadata()), 0.35F);
|
| 57 | }
|
| 58 | }
|
| 59 |
|
| 60 | this.addSmeltingRecipeForBlock(Blocks.coal_ore, new ItemStack(Items.coal), 0.1F);
|
| 61 | this.addSmeltingRecipeForBlock(Blocks.redstone_ore, new ItemStack(Items.redstone), 0.7F);
|
| 62 | this.addSmeltingRecipeForBlock(Blocks.lapis_ore, new ItemStack(Items.dye, 1, EnumDyeColor.BLUE.getDyeDamage()), 0.2F);
|
| 63 | this.addSmeltingRecipeForBlock(Blocks.quartz_ore, new ItemStack(Items.quartz), 0.2F);
|
| 64 | }
|
| 65 |
|
| 66 | /**
|
| 67 | * Adds a smelting recipe, where the input item is an instance of Block.
|
| 68 | */
|
| 69 | public void addSmeltingRecipeForBlock(Block input, ItemStack stack, float experience)
|
| 70 | {
|
| 71 | this.addSmelting(Item.getItemFromBlock(input), stack, experience);
|
| 72 | }
|
| 73 |
|
| 74 | /**
|
| 75 | * Adds a smelting recipe using an Item as the input item.
|
| 76 | */
|
| 77 | public void addSmelting(Item input, ItemStack stack, float experience)
|
| 78 | {
|
| 79 | this.addSmeltingRecipe(new ItemStack(input, 1, 32767), stack, experience);
|
| 80 | }
|
| 81 |
|
| 82 | /**
|
| 83 | * Adds a smelting recipe using an ItemStack as the input for the recipe.
|
| 84 | */
|
| 85 | public void addSmeltingRecipe(ItemStack input, ItemStack stack, float experience)
|
| 86 | {
|
| 87 | this.smeltingList.put(input, stack);
|
| 88 | this.experienceList.put(stack, Float.valueOf(experience));
|
| 89 | }
|
| 90 |
|
| 91 | /**
|
| 92 | * Returns the smelting result of an item.
|
| 93 | */
|
| 94 | public ItemStack getSmeltingResult(ItemStack stack)
|
| 95 | {
|
| 96 | for (Entry<ItemStack, ItemStack> entry : this.smeltingList.entrySet())
|
| 97 | {
|
| 98 | if (this.compareItemStacks(stack, (ItemStack)entry.getKey()))
|
| 99 | {
|
| 100 | return (ItemStack)entry.getValue();
|
| 101 | }
|
| 102 | }
|
| 103 |
|
| 104 | return null;
|
| 105 | }
|
| 106 |
|
| 107 | /**
|
| 108 | * Compares two itemstacks to ensure that they are the same. This checks both the item and the metadata of the item.
|
| 109 | */
|
| 110 | private boolean compareItemStacks(ItemStack stack1, ItemStack stack2)
|
| 111 | {
|
| 112 | return stack2.getItem() == stack1.getItem() && (stack2.getMetadata() == 32767 || stack2.getMetadata() == stack1.getMetadata());
|
| 113 | }
|
| 114 |
|
| 115 | public Map<ItemStack, ItemStack> getSmeltingList()
|
| 116 | {
|
| 117 | return this.smeltingList;
|
| 118 | }
|
| 119 |
|
| 120 | public float getSmeltingExperience(ItemStack stack)
|
| 121 | {
|
| 122 | for (Entry<ItemStack, Float> entry : this.experienceList.entrySet())
|
| 123 | {
|
| 124 | if (this.compareItemStacks(stack, (ItemStack)entry.getKey()))
|
| 125 | {
|
| 126 | return ((Float)entry.getValue()).floatValue();
|
| 127 | }
|
| 128 | }
|
| 129 |
|
| 130 | return 0.0F;
|
| 131 | }
|
| 132 | }
|
| 133 |
|