Minecraft Blogs / Tutorial

[1.5.2][ModLoader] Create your own mod! [OUTDATED]

  • 14,399 views, 3 today
  • 25
  • 14
  • 44
MusaTheLegend's Avatar MusaTheLegend
Retired Moderator
Level 56 : Grandmaster Necromancer
725

This tutorial will tell you how to create your own mod using ModLoader and MCP (MinecraftCodePack).
EDIT: POP REEELLLLLLL YEAAAAi.imgur.com/1pFVYET.png
ITS IN HERE! (Blocks, items, ores, foods, biomes, recipes, etc) MOBS COMING SOON!

Downloads:

Eclipse: www.eclipse.org/downloads/
Java JDK: www.oracle.com/technetwork/java/javase/downloads/index.html
ModLoader: www.minecraftforum.net/topic/75440-v152-risugamis-mods-updated/
MCP 1.5.2: www.mediafire.com/download.php?95vlzp1a4n4wjqw
Setting Up (Windows/Linux):
1. Download all the files and put them in a folder for organization.
2. Install Java JDK on your computer if you have not already done so.
3.Unzip MCP to a different folder.
4. Force Update Minecraft.
5. Install ModLoader into your minecraft.
6. Go to Run > %appdata% > Roaming > .minecraft > bin > minecraft. Copy the "bin" and "resources" folder and paste them into the "Jars" folder in MCP.
7. Run decompile.bat (Windows) or decompile.sh (Linux) in the MCP folder.
8. Run Eclipse and when it asks for a workspace directory, select the "eclipse" folder in MCP.

Setting Up (Mac):

1. Download all the files and put them in a folder for organization.
2. Install Java JDK on your computer if you have not already done so.
3.Unzip MCP to a different folder.
4. Force Update Minecraft.
5. Install ModLoader into your minecraft.
6. Go to ~/Library/Application Support/minecraft/ Copy the "bin" and "resources" folder and paste them into the "Jars" folder in MCP.
7. Open Terminal and type: cd YourMCPFolderHere
8. Type: bash decompile.sh
9. Run Eclipse and when it asks for a workspace directory, select the "eclipse" folder in MCP.

CREATING YOUR MOD!
===================

Creating your main mod file:

In Eclipse, open up Client > src > net.minecraft.src. Right click net.minecraft.src and go to New > Class. Name the class "mod_YourModName". I will name mine "mod_Musa". Open up your mod_YourModName and copy and paste this into it:
package net.minecraft.src;
public class mod_Musa extends BaseMod{
public void load(){

}
public String getVersion(){
return "blah";
}
}
Replace mod_Musa with mod_YourModName.

Creating a block:

public static final Block musaBlock = new BlockMusa(180, 0);
Put that line under public class mod_YourModName but above public void load. Rename musaBlock with "yourblocknameBlock" and rename BlockMusa with "BlockYourblockname". The (180, 0) is the ID of your block. Make sure its not conflicting with another block in Minecraft, and is under 256. Lets add some attributes to your block.
public static final Block musaBlock = new BlockMusa(180, 0).setHardness(1.0F).setResistance(5F);
.setHardness sets how hard it is to break. 0.0F is by hand, 1.0F is by a wooden pickaxe, 2.0F is by a stone pickaxe, etc. .setResistance is how easily it is destroyed by explosives. Lets add a texture to our block.
public static final Block musaBlock = new BlockMusa(180, 0).setHardness(1.0F).setResistance(5F).setUnlocalizedName("Musa Block")
("Musa Block") is the name of the file located at Mcp folder > jars > bin > minecraft > textures > blocks. Create a texture in your favorite photo editor, like Gimp or paint.net. Make a 16x16 transparent picture. Add some colors and detail to it. This will be how your block will look like in-game. Make sure to save the file as a .png. Mine would be "Musa Block.png". When you are writing the name of the file in your code, make sure it doesn't have the .png extension in it. Right click "net.minecraft.src" and go to New > Class. Name the class what you named the 2nd word in your code. (musaBlock = new BlockMusa, I would use BlockMusa) Mine would be New > Class > Name: BlockMusa.
package net.minecraft.src;
import java.util.Random;
public class BlockMusa extends Block {

public BlockMusa(int par1, int i){
super(par1, Material.rock);
this.setCreativeTab(CreativeTabs.tabBlock);
}

public int quantityDropped(int par1){
return (1);
}

public int idDropped(int par1, Random par2Random, int par3)
{
return mod_Musa.musaBlock.blockID;
}
]
Copy and paste all of the code above into your 2nd word class file (Mine is BlockMusa). (CreativeTabs.tabBlock); places your block in the "Blocks" tab in the Creative Menu. return (1); makes it so it drops only 1 of your block. In cases like redstone and lapiz ore, they drop multiple. That is because of that line of code. return mod_Musa.musaBlock.blockID; makes it so it drops the block "musaBlock". Change musaBlock to your first word in the code. Now all we need to do is register your block and give it a name. Under public void load, insert:
ModLoader.registerBlock(musaBlock);
ModLoader.addName(musaBlock, "Musa Block");
set registerBlock(musaBlock); to registerBlock(yourfirstwordBlock); the addName line gives your block a name. The name in here is the name it will have in-game. change musaBlock to your first word. The word in the quotation marks is the name it will have in-game. Set this to whatever you want. Click the green arrow in the top left of Eclipse, its the icon on the right of the bug icon. The green arrow will open up Minecraft. Once Minecraft loads up, create a new single player world. In it, go to creative mode. Go under the "Building Blocks" section of the menu. Your block should be the last block there. If its there, you did it all right! Congratulations, you just made a block. To create more than one block, since most tutorials don't tell you how, read the following. The line where you created your block (public static final Block musaBlock ... etc), repeat that but with another block name. Repeat making a new class for your second word (BlockMusa). Do the same copy/paste. Register and name your block under where you registered and named your first block.

Making an item:

Creating an item is much easier than making a block.
public static final Item musa = new Item(1035);
Put that line under the line public class mod_Yourmodnamehere extends BaseMod{ but above public void load. Change "musa" to the name of your item. Change (1035) to another ID. Make sure its not conflicting with another item. ID's for item must be ABOVE 256. Now lets add some attributes to our item.
public static final Item musa = new Item(1035).setUnlocalizedName("musa").setCreativeTab(CreativeTabs.tabMaterials);
This will load the texture "musa.png" located at MCPFolder > jars > bin > minecraft > textures > items. Create a texture for your item, make sure its 16x16 and saved as "youritemname.png". .setCreativeTab(CreativeTabs.tabMaterials); sets our item in the "Materials" tab in the Creative Menu. Lets add a name to our item. Write this under "public void load":
ModLoader.addName(musa, "Musa");
Adding a crafting/smelting recipe to our item/block:
To add a recipe for our item/block, write:
ModLoader.addRecipe(new ItemStack(musaBlock, 5), new Object[]
{
"XXX", "XXX", "XXX",
'X', musa
This will set the crafting recipe for our block "musaBlock". We will get 5 musaBlock's in return for this recipe. The X's, represent "musa's" (My item). Character.valueOf('#'), Block.dirt tells our mod to make the value of X a musa. "XXX", "XXX", "XXX" is the crafting recipe. Since a crafting table is a 3x3 table, we use 3 sets of 3 values. Its sorta like this:
"XXX" <--You see how when you look at it from top to bottom it forms a T-shape? Thats how it will be in the crafting
"XXX" <--table. The first set of quotation marks represent the top row of the crafting table. In this case we have 3
"XXX" <--X's. The 2nd set is the middle row, the 3rd set is the last row. Simple if you get it. Example: Iron ingots to an iron block would be "XXX", "XXX", "XXX'. Since each row has all 3 values filled with hashtags, you need 9 iron ingots to form one iron block. 'X', musa means that an 'X' = one musa. To add a block/item from the minecraft default, use Block.(blockname) or Item.(itemname). To use the item you made earlier, use 'X', youritemnamehere. To make the recipe use 2 or more items/block to craft the desired block/item, simply copy the character value. Example: A diamond pickaxe. It needs 3 diamonds on the top row, one stick in the middle of the middle row, and another stick in the middle of the last row. We will do that with the following code:
ModLoader.addRecipe(new ItemStack(diamondPickaxe(, 1), new Object[]
{
"DDD", " S ", " S ",
'D', Item.diamond, 'S', Item.stick
It will look like this in the crafting table:
"DDD" D = Diamond. S = Stick. As you can see on the left, it forms a diamond pickaxe (Minecraft logic).
" S "
" S "
Now lets add a smelting recipe, so we can lets say, smelt a "musaOre" and get a "musa". This is how we will do that. (I just created musaOre, so dont ask)
ModLoader.addSmelting(musaOre, new ItemStack(musa, 1), 1.0F);
(musaOre) = The block you are going to smelt in the furnace to get whatever. (musa, 1) is what you will get in return, in this case we are going to get a "musa" in return of smelting a musaOre. After the smelting recipe, we will get 1.0F EXP. Put that line of code under "public void load".

Creating a biome:

ModLoader.addBiome(BiomeGenBase.lapizHills);
Put that under "public void load". This will create a biome named lapizHills. On the side of Eclipse, open Client > src > net.minecraft.src. In net.minecraft.src, find BiomeGenBase.java. Put this in that, but make sure it is under the latest biome in that class. It should be jungleHills as this is YOUR first biome.
public static final BiomeGenBase lapizHills = (new BiomeGenLapiz(23)).setColor(2900485).setBiomeName("LapizHills").func_76733_a(5470985).setTemperatureRainfall(2.0F, 0.0F).setMinMaxHeight(0.3F, 1.5F);
Right click on net.minecraft.src and go to New > Class. BiomeGenLapiz Is mine. Name yours BiomeGen(BiomeName). Copy/paste this into it:
package net.minecraft.src;
public class BiomeGenLapiz extends BiomeGenBase{

public BiomeGenLapiz(int par1){
super(par1);
this.topBlock = (byte)Block.blockLapiz.blockID; //This is the block on the top. (Grass)
this.fillerBlock = (byte)Block.blockGold.blockID; //Block below. (Dirt)
}
}
This makes it so the hills we generate have Lapiz on the top, and gold on the bottom. Press the green arrow on the top left of eclipse. This opens minecraft. Create a new world and search for your biome, it should work!

Creating an ore:

First we have to make the ore block. Lets name ours a "Musa Ore". In coding, it will be oreMusa.
public static final Block oreMusa = new BlockMusaOre(183, 0).setHardness(3.0F).setResistance(3.0F).setUnlocalizedName("oreMusa").setCreativeTab(CreativeTabs.tabBlock);
Put that under "public void load". This creates an oreMusa (Musa Ore). Its template will be BlockMusaOre. Yours will be "oreYourorename" and "BlockYourorenameOre". Its id is 183. Its texture will be located in MCP > jars > bin > minecraft > blocks since this is a block. Its texture will be named oreMusa.png, in the coding, make sure to exclude the .png! Right click "net.minecraft.src", go to New > Class. Name it BlockYourorenamehereOre. Mine is BlockMusaOre. Put this into your BlockYourorenamehereOre class.
package net.minecraft.src;
import java.util.Random;
public class BlockMusaOre extends Block{
public BlockMusaOre(int par1, int i){
super(par1, Material.iron);
}

public int quantityDropped(int par1){
return (1);
}

public int idDropped(int par1, Random par2Random, int par3){
return mod_Musa.oreMusa.blockID;
}

}
quantityDropped return (1) means it will drop 1 of its block. return mod_Musa.oreMusa.blockID; makes it so it drops a "oreMusa". That is like iron and gold ore. They drop the ore, which you have to smelt in a furnace to get its ingot. In cases like Diamond Ore, it drops one "Diamond". The code for the diamond ore would be "return mod_Musa.diamond.itemID; So it will drop one diamond, and declaring it is an item with itemID. If you are dropping a block, make it blockID. Generating your ore in the world: So we have created an ore, and declared that it is an ore, and that it will drop an ore/item. Now we need to let it generate in our world. Go to your mod_Yourmodname class. Mine is mod_Musa. Go all the way to the bottom of it and copy/paste this into it:
public void generateSurface(World world, Random random, int i, int j){
for(int k = 0; k < 7; k++){
int randPosX = i + random.nextInt(16);
int randPosY = random.nextInt(48);
int randPosZ = j + random.nextInt(16);
(new WorldGenMinable(oreMusa.blockID, 8)).generate(world, random, randPosX, randPosY, randPosZ);
}
}
You can change k < 7 to the amount of veins per chunk loaded. Example: (k < 2) DO NOT change the randPosX(16) and randPosZ(16) or you will have chunk problems (Not good!). You can change randPosY (48). This is the maximum amount of height your veins will spawn in. (oreMusa.blockID, 8) is the ore thats being generated, and 8 is the maximum amount of your ore in one vein. You should now be able to found your block, but under the level 48.

TOOLS:

Now lets create some tools. You must go above and see the crafting recipe tutorial first!
public static final Item musaHoe = new ItemHoe(1204, EnumToolMaterial.MUSA).setCreativeTab(CreativeTabs.tabTools).setUnlocalizedName("hoeMusa");
public static final Item musaSpade = new ItemSpade(1205, EnumToolMaterial.MUSA).setCreativeTab(CreativeTabs.tabTools).setUnlocalizedName("spadeMusa");
public static final Item musaSword = new ItemSword(1206, EnumToolMaterial.MUSA).setCreativeTab(CreativeTabs.tabCombat).setUnlocalizedName("swordMusa");
public static final Item musaPickaxe = new ItemPickaxe(1207, EnumToolMaterial.Musa).setCreativeTab(CreativeTabs.tabTools).setUnlocalizedName("pickaxeMusa");
public static final Item musaAxe = new ItemAxe(1208, EnumToolMaterial.MUSA).setCreativeTab(CreativeTabs.tabTools).setUnlocalizedName("axeMusa");
Put all that above public void load and under public class mod_blahblahbagag. This creates all 5 tools, but using musa's! So therefor, musa tools. change musaHoe, musaSpade etc to youritemhereHoe, youritemhereSpade etc. Leave the ItemHoe, ItemSpade, ItemSword and all that alone. Beside ItemHoe, ItemSpade,etc, is a number. This number is the ID. Change EnumToolMaterial.MUSA to EnumToolMaterial.YOURITEMHERE. Change .setUnlocalizedName("axeMusa"); to "axeYourmaterialhere". This is the texture for your items. Create a 16x16 texture for each of your tools and save them all in MCP > jars > bin > minecraft > textures > item. Make sure to save them as axeMaterial.png or swordMaterial.png. In the coding make sure you dont include the .png extension! On the side of eclipse, go to Client > src > net.minecraft.src. Find the class EnumToolMaterial.java in that list. Open that up. There should be:
WOOD(0, 59, 2.0F, 0, 15),
STONE(1, 131, 4.0F, 1, 5),
IRON(2, 250, 6.0F, 2, 14),
EMERALD(3, 1561, 8.0F, 3, 10),
GOLD(0, 32, 12.0F, 0, 22);
These are the attributes for Wood tools, stone tools, iron tools, emerald tools, and gold tools. In the GOLD line, at the end of the line, remove the ";". Under the GOLD line make your materials line. Since I am making 'Musa Tools' mine would be MUSA. This is where the EnumToolMaterial.MUSA comes from in the tools coding. The first number in each line (Wood = 0, stone = 1, iron = 3, gold = 0) is the level of material it can harvest. If you set it to "3" it could harvest Diamond, iron, stone, gold. If you set it to "2" it could harvest iron, stone and gold. If its "1" Its only stone and gold. And if its 0, its iron and gold. Example: Wooden pickaxes cannot mine diamond, now can they? No. Thats because in the line for WOOD, its 0. Therefor it can mine iron, stone. So the first number is the level of material they can harvest, like I just said. The 2nd number is how many uses the material allows. If you look, gold only has 32, thats why it breaks so easily. Iron has 250, therefor it lasts LONGER than gold. (Recap: 1st number = material harvest. 2nd number = uses) The 3rd number is the strength of this tool material against blocks which it is effective against. The 4th number is the damage versus entities. The 5th and last number defines the natural enchantability factor of the material. Here is mine after my changes:
WOOD(0, 59, 2.0F, 0, 15),
STONE(1, 131, 4.0F, 1, 5),
IRON(2, 250, 6.0F, 2, 14),
EMERALD(3, 1561, 8.0F, 3, 10),
GOLD(0, 32, 12.0F, 0, 22), //You see how there is no ";" at the end of this line now? Replace the ";" with a comma (,)
MUSA(3, 1500, 12.0F, 2, 25); //Add a ";" at the end of this line! an ";" means you are closing this line of code.
I am making my tools so that they can break every material, from diamond to stone. It has 1500 uses, so it lasts long, but not too long. And you can easily enchant it. (25). Once your done with that, go back to your mod_Yourmodname class.
Adding a recipe and a name to your items:
ModLoader.addName(musaHoe, "Musa Hoe");
ModLoader.addRecipe(new ItemStack(musaHoe, 1), new Object[]
{
"** ", " X ", " X ",
'X', Item.stick, '*', musa
});

ModLoader.addName(musaSpade, "Musa Shovel");
ModLoader.addRecipe(new ItemStack(musaSpade, 1), new Object[]
{
" * ", " X ", " X ",
'X', Item.stick, '*', musa
});

ModLoader.addName(musaSword, "Musa Sword");
ModLoader.addRecipe(new ItemStack(musaSword, 1), new Object[]
{
" * ", " * ", " X ",
'X', Item.stick, '*', musa
});

ModLoader.addName(musaPickaxe, "Musa Pickaxe");
ModLoader.addRecipe(new ItemStack(musaPickaxe, 1), new Object[]
{
"***", " X ", " X ",
'X', Item.stick, '*', musa
});

ModLoader.addName(musaAxe, "Musa Axe");
ModLoader.addRecipe(new ItemStack(musaAxe, 1), new Object[]
{
" **", " X*", " X ",
'X', Item.stick, '*', musa
});
Change 'X', Item.stick, '*', musa To 'X', Item.stick, '*', youritemnamehere. Change all of the musaAxe, "Musa Axe"); (EXAMPLE) to yourtoolmaterialAxe, "In-gameName); You are now done your items. You have created their attributes, textures (maybe), and the names and recipes.

Making Food:

Put this under public class mod_Yourmodname extends .. etc. but above public void load.
public static final Item bacon = new ItemFood(1100, 6, 0.75F, true).setUnlocalizedName("bacon");
This will create an item named bacon, its texture will be named bacon and it will be saved in MCP > jars > bin > minecraft > textures > items. as a bacon.png. The first number (1100) is the id of our food. The 2nd is how many hunger pieces it fills (Half chicken bone icon thingys). The 3rd number is the saturation (the time before you get hungry, once again) (It must be between 0 and 1). The "true" is if you can feed your food item to wolves. true = yes, false = no. To add potion effects, add
public static final Item bacon = new ItemFood(1100, 6, 0.75F, true).setPotionEffect(Potion.hunger.id, 45, 0, 0.5F).setUnlocalizedName("bacon");
The first number is the potion ID. The 2nd number is how long your potion effect will last for (seconds). The 0.5F is the probability of getting the potion effect. 0 is never, 1 is always. 0.5F is in the middle. Its a 50/50 chance with 0.5F. To make it so you can eat your food even when your NOT hungry, add:
public static final Item bacon = new ItemFood(1100, 6, 0.75F, true).setPotionEffect(Potion.hunger.id, 45, 0, 0.5F).setAlwaysEdible().setUnlocalizedName("bacon");
You have now created your food item.

Grenades:

Lets create a simple grenade. Put this line under public class mod_Yourmodname but above public void load.
public static final Item grenade = new ItemGrenade(1037).setCreativeTab(CreativeTabs.tabTools);
This creates an item named grenade and uses the base ItemGrenade. Its ID is 1037 and it is located in the Tools tab in the creative menu. On the left of Eclipse, right click net.minecraft.src, New > Class and name it ItemGrenade. Copy/paste this into it:
package net.minecraft.src;
public class ItemGrenade extends Item{

public ItemGrenade(int par1){
super(par1);
this.maxStackSize = 64; //maximum size in a stack
this.setUnlocalizedName("grenade"); //icon
}

public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer){

if (!entityplayer.capabilities.isCreativeMode){
--itemstack.stackSize; //removes one when right clicked if not in creative
}

if (!world.isRemote){
world.spawnEntityInWorld(new EntityGrenade(world, entityplayer)); //spawns the grenade entity
}

return itemstack;
}

}

This sets the max stack size to 64, you can change it if you want, it makes it so you can spawn the grenade entity.
Make an icon in your favorite image editor of your grenade. Save it as "grenade.png". Put this file in MCP>Jars>Bin>Minecraft>Textures>Items. Right click net.minecraft.src again and go to New > Class, name it EntityGrenade. In that, copy/paste this:
package net.minecraft.src;
public class EntityGrenade extends EntityThrowable{

public EntityGrenade(World par1World){
super(par1World);
}
public EntityGrenade(World par1World, EntityLiving par2EntityLiving){
super(par1World, par2EntityLiving);
}
public EntityGrenade(World par1World, double par2, double par4, double par6){
super(par1World, par2, par4, par6);
}

protected void onImpact(MovingObjectPosition par1MovingObjectPosition){
if (par1MovingObjectPosition.entityHit != null){
par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0);
}
if (!this.worldObj.isRemote){
explode(); //explodes the grenade
}
if (!this.worldObj.isRemote){
this.setDead();
}
}

private void explode(){
if(!exploded){
exploded =
Tags

2 Update Logs

Update #2 : by MusaTheLegend 05/18/2013 1:07:52 amMay 18th, 2013

Added grenades tutorial.
LOAD MORE LOGS

Create an account or sign in to comment.

1
08/19/2013 12:58 am
Level 23 : Expert Zombie
MinerJohn
MinerJohn's Avatar
1
08/04/2013 12:06 pm
Level 41 : Master Pixel Painter
Spierzy
Spierzy's Avatar
Darn you! 1.5.2!!! D:
If you would take the time and update this I would be very grateful (you would earn: 1+ sub, a lot of + diamonds :P)
By the way whats the difference when you make a mod in a new update?
1
08/04/2013 1:26 pm
Level 56 : Grandmaster Necromancer
MusaTheLegend
MusaTheLegend's Avatar
I'm pretty sure all the coding is the same but just the setup which is different. I'm sure you can go to the Minecraft Forums and find a tutorial on the setup.
1
08/04/2013 4:27 pm
Level 41 : Master Pixel Painter
Spierzy
Spierzy's Avatar
Well, I have already checked the forums but I cant find anything for 1.6, mostly everything is 1 year old
1
08/04/2013 6:16 pm
Level 56 : Grandmaster Necromancer
MusaTheLegend
MusaTheLegend's Avatar
oh well, i lost interest in coding now so i stopped updating, but good luck finding help. i suggest pming www.planetminecraft.com/member/HyJaffa
1
06/15/2014 3:52 am
Level 3 : Apprentice Miner
JakeMinecraft6
JakeMinecraft6's Avatar
are you a modarater becuase your nam says "site modarater"
1
06/15/2014 10:55 am
Level 56 : Grandmaster Necromancer
MusaTheLegend
MusaTheLegend's Avatar
Yeah, I'm a forum mod
1
08/05/2013 7:04 am
Level 41 : Master Pixel Painter
Spierzy
Spierzy's Avatar
Right, thanks
1
07/20/2013 8:18 pm
Level 52 : Grandmaster Blob
gabe4356
gabe4356's Avatar
none of this works..
1
07/20/2013 8:47 pm
Level 56 : Grandmaster Necromancer
MusaTheLegend
MusaTheLegend's Avatar
hence the title, 1.5.2.
1
07/20/2013 8:52 pm
Level 52 : Grandmaster Blob
gabe4356
gabe4356's Avatar
no..i was using mcp 1.5.2 and modloader 1.5.2
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome