diff --git a/src/main/java/biomesoplenty/api/block/BOPWoodEnums.java b/src/main/java/biomesoplenty/api/block/BOPWoodEnums.java index 2aeabf1d7..e54f36497 100644 --- a/src/main/java/biomesoplenty/api/block/BOPWoodEnums.java +++ b/src/main/java/biomesoplenty/api/block/BOPWoodEnums.java @@ -30,7 +30,8 @@ public class BOPWoodEnums { return this.getName(); } - public boolean hasPlanks() { + public boolean hasPlanks() + { switch (this) { case GIANT_FLOWER: case DEAD: return false; @@ -38,6 +39,15 @@ public class BOPWoodEnums return true; } } + public boolean canMakeCharcoal() + { + switch (this) { + case GIANT_FLOWER: + return false; + default: + return true; + } + } } diff --git a/src/main/java/biomesoplenty/common/handler/FurnaceFuelHandler.java b/src/main/java/biomesoplenty/common/handler/FurnaceFuelHandler.java new file mode 100644 index 000000000..5fe33fe68 --- /dev/null +++ b/src/main/java/biomesoplenty/common/handler/FurnaceFuelHandler.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright 2014, the Biomes O' Plenty Team + * + * This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License. + * + * To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. + ******************************************************************************/ + +package biomesoplenty.common.handler; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.lang3.tuple.Pair; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.common.IFuelHandler; + +public class FurnaceFuelHandler implements IFuelHandler +{ + private Map, Integer> itemMetaFuelList = new HashMap, Integer>(); + private Map itemFuelList = new HashMap(); + + @Override + public int getBurnTime(ItemStack fuel) { + return getFuelValue(fuel); + } + + // register an item with a specific meta value as a fuel + public void addFuel(Item item, int metadata, int value) + { + itemMetaFuelList.put(Pair.of(item, metadata), value); + } + + // register an item as a fuel (for any meta value) + public void addFuel(Item item, int value) + { + itemFuelList.put(item, value); + } + + public void addFuel(Block block, int metadata, int value) + { + addFuel(Item.getItemFromBlock(block), metadata, value); + } + + public void addFuel(Block block, int value) + { + addFuel(Item.getItemFromBlock(block), value); + } + + public int getFuelValue(ItemStack stack) + { + System.out.println("testing for fuel "+stack.getDisplayName()); + if (stack == null) {return 0;} + Item item = stack.getItem(); + if (item == null) {return 0;} + Pair pair = Pair.of(item, stack.getItemDamage()); + + // see if the specific item/meta combination is registered + if (itemMetaFuelList.containsKey(pair)) + { + System.out.println("specific match"); + return itemMetaFuelList.get(pair); + } + + // see if the item in general is registered + if (itemFuelList.containsKey(item)) + { + System.out.println("general match"); + return itemFuelList.get(item); + } + + // otherwise no value as fuel + return 0; + } + +} \ No newline at end of file diff --git a/src/main/java/biomesoplenty/common/init/ModCrafting.java b/src/main/java/biomesoplenty/common/init/ModCrafting.java index 5cce88e8e..431877f18 100644 --- a/src/main/java/biomesoplenty/common/init/ModCrafting.java +++ b/src/main/java/biomesoplenty/common/init/ModCrafting.java @@ -24,6 +24,7 @@ import biomesoplenty.common.block.BlockBOPPlant; import biomesoplenty.common.block.BlockBones; import biomesoplenty.common.block.BlockGem; import biomesoplenty.common.block.BlockHive; +import biomesoplenty.common.handler.FurnaceFuelHandler; import biomesoplenty.common.item.ItemDart; import biomesoplenty.common.item.ItemJarFilled; import net.minecraft.init.Blocks; @@ -39,6 +40,7 @@ public class ModCrafting public static void init() { addCraftingRecipies(); + addSmeltingRecipes(); } @@ -310,9 +312,9 @@ public class ModCrafting GameRegistry.addShapedRecipe(new ItemStack(Items.rotten_flesh), new Object[] {"FFF", "FPF", "FFF", 'F', new ItemStack(BOPItems.fleshchunk), 'P', new ItemStack(BOPItems.jar_filled, 1, ItemJarFilled.JarContents.POISON.ordinal())}); //Bone Segments > Bonemeal - GameRegistry.addShapelessRecipe(new ItemStack(Items.dye, 3, 15), new Object[] {((BlockBones)BOPBlocks.bone_segment).getVariantItem(BlockBones.BoneType.SMALL)}); - GameRegistry.addShapelessRecipe(new ItemStack(Items.dye, 6, 15), new Object[] {((BlockBones)BOPBlocks.bone_segment).getVariantItem(BlockBones.BoneType.MEDIUM)}); - GameRegistry.addShapelessRecipe(new ItemStack(Items.dye, 12, 15), new Object[] {((BlockBones)BOPBlocks.bone_segment).getVariantItem(BlockBones.BoneType.LARGE)}); + GameRegistry.addShapelessRecipe(new ItemStack(Items.dye, 3, EnumDyeColor.WHITE.getDyeDamage()), new Object[] {((BlockBones)BOPBlocks.bone_segment).getVariantItem(BlockBones.BoneType.SMALL)}); + GameRegistry.addShapelessRecipe(new ItemStack(Items.dye, 6, EnumDyeColor.WHITE.getDyeDamage()), new Object[] {((BlockBones)BOPBlocks.bone_segment).getVariantItem(BlockBones.BoneType.MEDIUM)}); + GameRegistry.addShapelessRecipe(new ItemStack(Items.dye, 12, EnumDyeColor.WHITE.getDyeDamage()), new Object[] {((BlockBones)BOPBlocks.bone_segment).getVariantItem(BlockBones.BoneType.LARGE)}); //Honeycombs GameRegistry.addShapedRecipe(new ItemStack(BOPBlocks.hive, 1, BlockHive.HiveType.HONEYCOMB.ordinal()), new Object [] {"##", "##", '#', new ItemStack(BOPItems.honeycomb)}); @@ -329,4 +331,36 @@ public class ModCrafting } + + public static void addSmeltingRecipes() + { + + // Register smelting recipes + GameRegistry.addSmelting(Blocks.dirt, new ItemStack(BOPBlocks.dried_dirt), 0F); + GameRegistry.addSmelting(BlockBOPPlant.getVariantItem(AllPlants.TINYCACTUS), new ItemStack(Items.dye, 1, EnumDyeColor.GREEN.getDyeDamage()), 0.2F); + GameRegistry.addSmelting(BOPItems.mudball, new ItemStack(BOPItems.mud_brick), 0F); + for (AllWoods wood : AllWoods.values()) + { + if (wood.canMakeCharcoal()) + { + GameRegistry.addSmelting(BlockBOPLog.getVariantItem(wood), new ItemStack(Items.coal, 1, 1), 15F); + } + } + + // Register items which can be used as fuel + FurnaceFuelHandler bopFuel = new FurnaceFuelHandler(); + GameRegistry.registerFuelHandler(bopFuel); + + bopFuel.addFuel(BOPBlocks.sapling_0, 100); + bopFuel.addFuel(BOPBlocks.sapling_1, 100); + bopFuel.addFuel(BOPBlocks.sapling_2, 100); + bopFuel.addFuel(BOPBlocks.wood_slab_0, 150); + bopFuel.addFuel(BOPBlocks.wood_slab_1, 150); + // Note, we don't have to add all the other wood blocks - by default any block with Material = wood burns with value of 300 + // See TileEntityFurnace.getItemBurnTime() + + bopFuel.addFuel(BOPItems.ash, 400); // TODO: really? 400? Ash is already burnt but burns better than wooden planks? + + } + }