Using ModLoader to add a new block
From Mod Coder Pack
This tutorial is written for anyone new to Minecraft modding. It is assumed that you have a basic knowledge of java, an have a compiler setup and working, but no knowledge of the minecraft system.
Contents |
Setting up
- Download MCP.
- Extract the zip into a folder somewhere on your computer.
- run Minecraft with the force update option. (you need a clean minecraft.jar)
- Copy the bin and resources folders from your .minecraft directory into MCP/jars
- Download ModLoader
- Copy contents of modloader archive into MCP/jars/bin/minecraft.jar
- Open up a command prompt and cd to MCP
- Run decompile
- Wait for it to decompile.
Making your first mod
- Create the file MCP/src/minecraft/net/minecraft/src/mod_myfirstmod.java (This is just what is going to be used in these examples)
- Copy the following into the file
package net.minecraft.src; public class mod_myfirstmod extends BaseMod{ public mod_myfirstmod(){ } public String Version(){ return "0.1"; } }
At the moment, this mod does nothing interesting.
Making the mod do something
For this tutorial, we're going to make a new gravity affected block.
Replace the constructor with the following code.
public mod_myfirstmod(){ int gravistoneId=100; //Adds a new gravity affected block with a cobblestone texture Block gravistone=new BlockSand(gravistoneId, 16); //Makes the block usable ModLoader.RegisterBlock(gravistone); //Add a recipe for the block, in this case, a cobblestone surrounded by sand. //Makes 8 gravistone ModLoader.AddRecipe(new ItemStack(gravistone, 8), new Object[]{ "SSS", "SCS", "SSS", 'C', Block.cobblestone, 'S', Block.sand }); }
This mod is now ready to test.
- Save the file
- Alt-Tab to the command prompt window and run recompile
- Wait for it to compile and then run startclient
- Gather some sand and some cobblestone and test out the block
Fixing a few problems
As you may have noticed while playing with your new block, the gravistone is incredibly weak and it doesn't have a name. We are going to fix those now.
Edit the file and put the following lines just below the line that adds the block
gravistone.setHardness(0.8F); //Makes the gravistone somewhat resistant gravistone.setBlockName("gravistone"); //Gives the block an internal name //Adds a name for the block. This is the name that you will see when you hover over it in your inventory. ModLoader.AddName(gravistone, "Gravistone");
Time to test again.
- Save the file
- Alt-Tab to the command prompt window and run recompile
- Wait for it to compile and then run startclient
- Test it and make sure that the block works as you would like it to.
Congratulations, you have made your first ModLoader compatible mod. However, the mod only works on your computer.
Making the mod suitable for release
This bit is quite simple really.
- Switch to the command prompt
- Recompile (only needed if you modified the code since last time)
- Run reobfuscate
- Wait
- Open up MCP/reobf/minecraft
- Get the file mod_myfirstmod.class and put it in a zip file.
- Copy the zip file into your .minecraft/mods folder
- Install ModLoader
- Start Minecraft normally and test the mod.
- Don't publish the mod on minecraft forum, else there will be lots of identical mods on the forum.