Modding: Adding a fuel item

In this tutorial I will teach you how to add an item that can be used in a furnace as fuel. I will use this file to start with.


package Tutorial.common;

import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraftforge.common.DungeonHooks;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = “YourName_ModName”, name = “ModName”, version = “Version number”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
public static Block oreblock;

public static Item youritem;

public static Item yourfood;

@SidedProxy(clientSide = “Tutorial.client.ClientProxyTutorial”, serverSide = “Tutorial.common.CommonProxyTutorial”)
    public static CommonProxyTutorial proxy;

@Init
public void load(FMLInitializationEvent event) 
{
oreblock = new BlockOres(230, 0).setStepSound(Block.soundStoneFootstep).setHardness(3F).setResistance(1.0F).setBlockName(“oreblock”);

GameRegistry.registerBlock(oreblock);

LanguageRegistry.addName(oreblock, “Your Ore”);

youritem = new ItemTutorial(550).setIconIndex(1).setItemName(“youritem”);

LanguageRegistry.addName(youritem, “Your Item”);

proxy.registerRenderThings();

DungeonHooks.addDungeonLoot(new ItemStack(youritem), 10, 2, 5);
DungeonHooks.setDungeonLootTries(50);

yourfood = new ItemTutorialFood(551, 8, true).setIconIndex(3).setItemName(“yourfood”);
LanguageRegistry.addName(yourfood, “Your Food”);
}
}


To add fuel items you will have to add this one line to your file.


GameRegistry.registerFuelHandler(new TutorialFuel());


GameRegistry has a method called registerFuelHandler. In the parameter you will have to add a new class. In that class we are going to place the fuel items.
The whole mod file should now look like this.


package Tutorial.common;

import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraftforge.common.DungeonHooks;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = “YourName_ModName”, name = “ModName”, version = “Version number”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
public static Block oreblock;

public static Item youritem;

public static Item yourfood;

@SidedProxy(clientSide = “Tutorial.client.ClientProxyTutorial”, serverSide = “Tutorial.common.CommonProxyTutorial”)
    public static CommonProxyTutorial proxy;

@Init
public void load(FMLInitializationEvent event) 
{
oreblock = new BlockOres(230, 0).setStepSound(Block.soundStoneFootstep).setHardness(3F).setResistance(1.0F).setBlockName(“oreblock”);

GameRegistry.registerBlock(oreblock);

LanguageRegistry.addName(oreblock, “Your Ore”);

youritem = new ItemTutorial(550).setIconIndex(1).setItemName(“youritem”);

LanguageRegistry.addName(youritem, “Your Item”);

proxy.registerRenderThings();

DungeonHooks.addDungeonLoot(new ItemStack(youritem), 10, 2, 5);
DungeonHooks.setDungeonLootTries(50);

yourfood = new ItemTutorialFood(551, 8, true).setIconIndex(3).setItemName(“yourfood”);
LanguageRegistry.addName(yourfood, “Your Food”);

GameRegistry.registerFuelHandler(new TutorialFuel());
}
}


This is what the TutorialFuel file should look like.


package Tutorial.common;

import net.minecraft.src.ItemStack;
import cpw.mods.fml.common.IFuelHandler;

public class TutorialFuel implements IFuelHandler 
{
public int getBurnTime(ItemStack fuel) 
{

}
}


To add a fuel you will have to add this.


if(fuel.itemID == Tutorial.youritem.shiftedIndex)
return 1000;
else
return 0;


fuel is the name of the itemstack. The .itemID changes the itemstack into a number. With the double = java checks if the thing after it is the same (1 = makes it the same). The thing it should check is if the fuel has the id of the item we have made before. If it does have the same id the smelting time will be 1000 ticks. This is 50 seconds. For example coal is 1600 ticks. If the fuel is not the item it will return 0 making all the other items that should not be burnable not fuel.

The whole file should look like this.


package Tutorial.common;

import net.minecraft.src.ItemStack;
import cpw.mods.fml.common.IFuelHandler;

public class TutorialFuel implements IFuelHandler 
{
public int getBurnTime(ItemStack fuel) 
{
if(fuel.itemID == Tutorial.youritem.shiftedIndex)
return 1000;
else
return 0;
}
}


This is all you have to do for the item to become a fuel.
If you want to add some more items or blocks to this file you can simply add another if() to the file.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">