Hello, and welcome to my modding tutorial thread. Here I will be posting various heavily requested tutorials from and intermediate level of modding! Feel free to post requests or bug reports etc and the more comments/thumbs up I get, the more tutorials I will write. So with that said, lets get started!
I'm assuming you have already set up your environment with MCP ( Currently version 7.23) and Forge 6.4.x and if not there are plenty of tutorials on how to do so.
[1/12/12]Another Tutorial coming later. Probbably on interaction with blocks
[25/11/2012] Added Metadata Block Tutorial
Fixed some derps in code ( I blame tiredness )
Basic Item
In this tutorial, I'm going to show you how to create your very first Item using the Minecraft Forge API.
First of All, we need a main mod class, I'm going to walk you through my one so here it is:
[/left]
public class NewItemMod {
public static Item item;
@Init
public void Init(FMLInitializationEvent event){
item = new Item(2000).setIconIndex(0).setItemName("item");
LanguageRegistry.addName(item,"This is the in-game name here!");
item.setCreativeTab(CreativeTabs.decoration);
}
}
This creates a new Item called item, gives it the Item ID of 2000(Out of 24000), sets the position in the spritesheet of 0(The image it will use) and gives it a name ID of "item"
We then add the ingame name using
LanguageRegistry.addName(item,"This is the in-game name here!");
and then we can add our item to a creative tab using
item.setCreativeTab(CreativeTabs.decoration);
Then you can launch the game and your item should be there!
NOTE: You will need to add missing imports as I wrote this tutorial from scratch and didn't include the imports but if you use eclipse, It should tell you what you need to add
Making Items Do Things When Right-Clicked
This is a very simple tutorial, all you need to do is open your Item class i.e NewItem.class (Not your MainMod.class) and add this code
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
//You can have any action here. I'm going to add a chat message.
ModLoader.getMinecraftInstance().thePlayer.addChatMessage("This is a right click action");
return par1ItemStack;
}
It is called when the Item is right clicked and adds a chat message "This is a right click action".
Now you should be able to launch Minecraft and right-click your Item and get this chat message
Custom Creative Tab
In this tutorial, I'm going to teach you how to create a new creative tab, using forge, that you can add your own or vanilla blocks/items.
So first of all we need our main class which should look something like this:
package eb99;
import net.minecraft.src.Block;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.Material;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.GameRegistry;
@Mod(modid = "ModID", name = "modname", version = "version number")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tests {
public static CreativeTabs tab;
@cpw.mods.fml.common.Mod.Init
public void Init(FMLInitializationEvent event){
tab = new Tab(12, "Tab");
}
}
You can see that we have
public static CreativeTabs tab;
to define a new tab and then
tab = new Tab(12,"Tab")
which tells the game that its a new instance of the Tab Class which we will write later, gives it a tab position of 12 (At the start of page 2) and a unique ID of "Tab"
We are now going to write the Tab Code:
package eb99;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
import net.minecraft.src.Block;
import net.minecraft.src.CreativeTabs;
public final class Tab extends CreativeTabs
{
public Tab(int par1, String par2Str)
{
super(par1, par2Str);
}
@SideOnly(Side.CLIENT)
public int getTabIconItemIndex()
{
return Block.glass.blockID
}
public String getTranslatedTabLabel()
{
return "Tests";
}
}
This Creates a new tab which extends CreativeTabs. We use the getTabIconFromIndex() method to determine what the tab uses as its icon. This can be a custom block or a vanilla block then we use the getTranslatedTabLabel() method to give the in-game name to that tab.
Now upon launching the game, in creative, you should have 2 arrows to go back and foward. If you were to navigate to the second page you should see your tab which is fully clickable.
Configuration Files
In this tutorial, I'm going to show you how to set up a configuration system for blocks. First you need to have a basic block ( I'll add a tutorial if one is requested but there are plenty out there ) then you will need to remove the block ID from where you define the block i.e:
block = new Block(200,0,Material.rock);
and replace it with
block = new Block(newBlockID,0,Material.rock);
and you need a new int called newBlockID
public static int newBlockID;
Now to set the value of this ID we are going to use this bit of code:
@PreInit
public void preInit(FMLPreInitializationEvent event) {
config.load();
Configuration config = new Configuration(event.getSuggestedConfigurationFile());
newBlockID = config.getBlock("What It will say next to the ID in the config file goes here", 2000).getInt();
config.save();
}
We define a new property which later gets parsed as an int as the value of newBlockID, we give it a name in the file and a default ID of 2000
Now you have a config file which will generate in yourMCPWorkspace/jars/config/modname.cfg
Block Metadata(Several Blocks In One ID)
Block metadata allows you to have up to 16 blocks under 1 ID which allows for greater compatibility and ID management. To start with you're going to require a block defined like this:
public static Block metadataTestBlock;
then in your'e initialization are i.e
@Init
public void Init(FMLInitializationEvent event) {
metadataTestBlock = new MetadataTestBlock(2000);
}
2000 is the ID that it will start at then followed by 2000:1, 2000:2 etc etc
Then, you will need to create a new class called MetadataTestBlock and put into it this code:
package net.minecraft.src;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
import java.util.List;
import net.minecraft.src.Block;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Material;
public class MetadataTestBlock extends Block
{
public MetadataTestBlock(int ID)
{
super(ID, Material.rock);
setHardness(1F);
setResistance(3F);
}
@SideOnly(Side.CLIENT)
public String getTextureFile() {
return "Your Image File Here i.e /testmod/Block.png";
}
@SideOnly(Side.CLIENT)
public int getBlockTextureFromSideAndMetadata(int i, int l) {
switch (l) {
case 0:
return 0;
case 1: return 1;
case 2: return 2;
case 3: return 3;
case 4: return 4;
case 5: return 5;
case 6: return 6;
case 7: return 7;
case 8: return 8;
case 9: return 9; }
return 0;
}
public int damageDropped(int par1)
{
return par1;
}
public void getSubBlocks(int i, CreativeTabs tab, List list)
{
list.add(new ItemStack(i, 1, 0));
list.add(new ItemStack(i, 1, 1));
list.add(new ItemStack(i, 1, 2));
list.add(new ItemStack(i, 1, 3));
list.add(new ItemStack(i, 1, 4));
list.add(new ItemStack(i, 1, 5));
list.add(new ItemStack(i, 1, 6));
list.add(new ItemStack(i, 1, 7));
list.add(new ItemStack(i, 1, 8));
list.add(new ItemStack(i, 1, 9));
}
}
You MUST remember to change the image file in the getTextureFile() method.
Next you will need another class file called MetadataTestBlockItem and inside it place this code:
package TechCraft;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.ItemBlock;
import net.minecraft.src.ItemStack;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
public class MetadataTestBlockItem extends ItemBlock
{
public MetadataTestBlockItem(int par1)
{
super(par1);
setMaxDamage(0);
setHasSubtypes(true);
}
public String getItemNameIS(ItemStack i) {
switch (i.getItemDamage()) {
case 0: return "Name 1";
case 1: return "Name 2";
case 2: return "Name 3";
case 3: return "Name 4";
case 4: return "Name 5";
case 5: return "Name 6";
case 6: return "Name 7";
case 7: return "Name 8";
case 8: return "Name 9";
case 9: return "Name 10"; }
return "";
}
public int getMetadata(int par1)
{
return par1;
}
@SideOnly(Side.CLIENT)
public int getIconFromDamage(int par1)
{
return YOURMAINMODCLASSHERE.metadataTestBlock.getBlockTextureFromSideAndMetadata(2, par1);
}
}
Once again you need to input your main mod class (Where you defined the new block) in getIconFromDamage(int par1) and in the switch statement in getItemNameIS() where there is 10 cases as you can see and you can remove or add cases up to case 15 : return "Name 15". Obviously these names are the just a unique ID but feel free to change them
Now we need to revisit the main file (where you defined the block) and add into the initialization part these two bits of code
public static String[] brickName = { "White","Red","Lime","Light Blue","Yellow","Purple","Green","Orange","Dark Green","Black"};
for(int i = 0; i < 10; i++) {
LanguageRegistry.addName(new ItemStack(metadataTestBlock,1,i),metadataTestBlockNames[i] + " Stone Brick");
}
This adds the names using a for loop. I'm using a stone brick example which collects the name from the value of i in the loop aswell as cycling through the metadata ID at the same time. We then register the block using the MetadataTestBlockItem.Class that we wrote earlier in the code shown above. Now you should have all the blocks but we need to add it to creative so we add this code and then we are done:
Why use a static ID when you could get a unique ID? If you use a static one you will get compatibility issues...
That will be changed later when I explain config files ( probably my next tutorial) as I didnt want to go into adding a config system in a simple tutorial
EDIT: Sorry misunderstood you, thought you were on about blocks. Yes you're right I should have used
Yep here it is: http://files.minecraftforge.net/
Just go there and select any 1.4.5 download
I'll add it to the main thread later
That will be changed later when I explain config files ( probably my next tutorial) as I didnt want to go into adding a config system in a simple tutorial
EDIT: Sorry misunderstood you, thought you were on about blocks. Yes you're right I should have used
CreativeTabs.getNextID()
instead of 12. I'll go update the tutorial now
Hey I just made a new creative tab and its works and all but I cant put my stuff there I changed the setCreativeTab to my tab but there are not in the tab in-game..
Hey I just made a new creative tab and its works and all but I cant put my stuff there I changed the setCreativeTab to my tab but there are not in the tab in-game..
Could you send me your code in a code spoiler please?, I'll take a look and hunt down the problem.
EDIT: Wow just seen your spoiler, the zoo mod looks epic seen quite alot on it before!
package oded.paranoiacraft;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
import net.minecraft.src.Block;
import net.minecraft.src.CreativeTabs;
public class testTab extends CreativeTabs
{
public testTab(int par1, String par2Str)
{
super(par1, par2Str);
}
@SideOnly(Side.CLIENT)
public int getTabIconItemIndex()
{
return test.testBlock.blockID;
}
public String getTranslatedTabLabel()
{
return "test Tab";
}
}
Main:
public static CreativeTabs testTab = new testTab(CreativeTabs.getNextID(), "testTab");
By the way Thanks
Are you trying to add blocks with metadata. If so I had this problem earlier and had to use some hacky workarounds and also where are you adding the block to the tab (In the block file i.e NewBlock.class or in your main mod file)
Yes sorry I don't know the answer unless in your .minecraft there is a forge-modloader.log or something along those lines? You're using this for a playing way right? you're not intending to mod?
Yes sorry I don't know the answer unless in your .minecraft there is a forge-modloader.log or something along those lines? You're using this for a playing way right? you're not intending to mod?
I'm assuming you have already set up your environment with MCP ( Currently version 7.23) and Forge 6.4.x and if not there are plenty of tutorials on how to do so.
MCP 7.23 (MC 1.4.4 & 1.4.5 compatible):http://mcp.ocean-lab...hp/MCP_Releases
Forge 6.4.x(Select any 1.4.5 build(Preferably the latest build)):http://files.minecraftforge.net/
This creates a new Item called item, gives it the Item ID of 2000(Out of 24000), sets the position in the spritesheet of 0(The image it will use) and gives it a name ID of "item"
We then add the ingame name using
and then we can add our item to a creative tab using
Then you can launch the game and your item should be there!
NOTE: You will need to add missing imports as I wrote this tutorial from scratch and didn't include the imports but if you use eclipse, It should tell you what you need to add
It is called when the Item is right clicked and adds a chat message "This is a right click action".
Now you should be able to launch Minecraft and right-click your Item and get this chat message
In this tutorial, I'm going to teach you how to create a new creative tab, using forge, that you can add your own or vanilla blocks/items.
So first of all we need our main class which should look something like this:
You can see that we have
to define a new tab and then
which tells the game that its a new instance of the Tab Class which we will write later, gives it a tab position of 12 (At the start of page 2) and a unique ID of "Tab"
We are now going to write the Tab Code:
This Creates a new tab which extends CreativeTabs. We use the getTabIconFromIndex() method to determine what the tab uses as its icon. This can be a custom block or a vanilla block then we use the getTranslatedTabLabel() method to give the in-game name to that tab.
Now upon launching the game, in creative, you should have 2 arrows to go back and foward. If you were to navigate to the second page you should see your tab which is fully clickable.
In this tutorial, I'm going to show you how to set up a configuration system for blocks. First you need to have a basic block ( I'll add a tutorial if one is requested but there are plenty out there ) then you will need to remove the block ID from where you define the block i.e:
and replace it with
and you need a new int called newBlockID
Now to set the value of this ID we are going to use this bit of code:
We define a new property which later gets parsed as an int as the value of newBlockID, we give it a name in the file and a default ID of 2000
Now you have a config file which will generate in yourMCPWorkspace/jars/config/modname.cfg
Block metadata allows you to have up to 16 blocks under 1 ID which allows for greater compatibility and ID management. To start with you're going to require a block defined like this:
then in your'e initialization are i.e
2000 is the ID that it will start at then followed by 2000:1, 2000:2 etc etc
Then, you will need to create a new class called MetadataTestBlock and put into it this code:
You MUST remember to change the image file in the getTextureFile() method.
Next you will need another class file called MetadataTestBlockItem and inside it place this code:
Once again you need to input your main mod class (Where you defined the new block) in getIconFromDamage(int par1) and in the switch statement in getItemNameIS() where there is 10 cases as you can see and you can remove or add cases up to case 15 : return "Name 15". Obviously these names are the just a unique ID but feel free to change them
Now we need to revisit the main file (where you defined the block) and add into the initialization part these two bits of code
and
This adds the names using a for loop. I'm using a stone brick example which collects the name from the value of i in the loop aswell as cycling through the metadata ID at the same time. We then register the block using the MetadataTestBlockItem.Class that we wrote earlier in the code shown above. Now you should have all the blocks but we need to add it to creative so we add this code and then we are done:
Now we are done, Any errors please contact me either through a PM or a post and I will fix the tutorial where I see fit
Not Yet Done
Not Yet Done
Not Yet Done
Coming VERY Soon!
Check Out My Modding Tutorials at http://www.minecraftforum.net/topic/1567641-144145forgeintermediateeb99s-modding-tutorials/page__view__findpost__p__19197074
Check Out My Modding Tutorials at http://www.minecraftforum.net/topic/1567641-144145forgeintermediateeb99s-modding-tutorials/page__view__findpost__p__19197074
Author of the Clarity, Serenity, Sapphire & Halcyon shader packs for Minecraft: Java Edition.
My Github page.
The entire Minecraft shader development community now has its own Discord server! Feel free to join and chat with all the developers!
Yep here it is: http://files.minecraftforge.net/
Just go there and select any 1.4.5 download
I'll add it to the main thread later
That will be changed later when I explain config files ( probably my next tutorial) as I didnt want to go into adding a config system in a simple tutorial
EDIT: Sorry misunderstood you, thought you were on about blocks. Yes you're right I should have used instead of 12. I'll go update the tutorial now
Check Out My Modding Tutorials at http://www.minecraftforum.net/topic/1567641-144145forgeintermediateeb99s-modding-tutorials/page__view__findpost__p__19197074
Did u replace your minecraft.jar with the 1.4.5 version?
Check Out My Modding Tutorials at http://www.minecraftforum.net/topic/1567641-144145forgeintermediateeb99s-modding-tutorials/page__view__findpost__p__19197074
Hey I just made a new creative tab and its works and all but I cant put my stuff there I changed the setCreativeTab to my tab but there are not in the tab in-game..
Could you send me your code in a code spoiler please?, I'll take a look and hunt down the problem.
EDIT: Wow just seen your spoiler, the zoo mod looks epic seen quite alot on it before!
Check Out My Modding Tutorials at http://www.minecraftforum.net/topic/1567641-144145forgeintermediateeb99s-modding-tutorials/page__view__findpost__p__19197074
Yes, I did.It also said something like "TMI is starting minecraft"
Has this ever happened to you?
No as i don't use TMI could you possibly obtain the crash log for me plz? And ill try make sense of it
EDIT: What forge build are u using?
Check Out My Modding Tutorials at http://www.minecraftforum.net/topic/1567641-144145forgeintermediateeb99s-modding-tutorials/page__view__findpost__p__19197074
Sure here:
Tab:
Main:
By the way Thanks
Reply:No as i don't use TMI could you possibly obtain the crash log for me plz? And ill try make sense of it
EDIT: What forge build are u using?
I am using the latest 1.4.5 forge
Oh and there wasn't a crash log. It didnt crash.
Are you trying to add blocks with metadata. If so I had this problem earlier and had to use some hacky workarounds and also where are you adding the block to the tab (In the block file i.e NewBlock.class or in your main mod file)
Check Out My Modding Tutorials at http://www.minecraftforum.net/topic/1567641-144145forgeintermediateeb99s-modding-tutorials/page__view__findpost__p__19197074
I just needed to define it before the block.. My bad xD
Yes sorry I don't know the answer unless in your .minecraft there is a forge-modloader.log or something along those lines? You're using this for a playing way right? you're not intending to mod?
Check Out My Modding Tutorials at http://www.minecraftforum.net/topic/1567641-144145forgeintermediateeb99s-modding-tutorials/page__view__findpost__p__19197074
I am intending to mod.
well then you shouldnt be putting forge into the jar have u got mcp set up?
Check Out My Modding Tutorials at http://www.minecraftforum.net/topic/1567641-144145forgeintermediateeb99s-modding-tutorials/page__view__findpost__p__19197074