Using ModLoader to add a new block

From Mod Coder Pack

Jump to: navigation, search

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

  1. Download MCP.
  2. Extract the zip into a folder somewhere on your computer.
  3. run Minecraft with the force update option. (you need a clean minecraft.jar)
  4. Copy the bin and resources folders from your .minecraft directory into MCP/jars
  5. Download ModLoader
  6. Copy contents of modloader archive into MCP/jars/bin/minecraft.jar
  7. Open up a command prompt and cd to MCP
  8. Run decompile
  9. Wait for it to decompile.

Making your first mod

  1. Create the file MCP/src/minecraft/net/minecraft/src/mod_myfirstmod.java (This is just what is going to be used in these examples)
  2. 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.

  1. Save the file
  2. Alt-Tab to the command prompt window and run recompile
  3. Wait for it to compile and then run startclient
  4. 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.

  1. Save the file
  2. Alt-Tab to the command prompt window and run recompile
  3. Wait for it to compile and then run startclient
  4. 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.

  1. Switch to the command prompt
  2. Recompile (only needed if you modified the code since last time)
  3. Run reobfuscate
  4. Wait
  5. Open up MCP/reobf/minecraft
  6. Get the file mod_myfirstmod.class and put it in a zip file.
  7. Copy the zip file into your .minecraft/mods folder
  8. Install ModLoader
  9. Start Minecraft normally and test the mod.
  10. Don't publish the mod on minecraft forum, else there will be lots of identical mods on the forum.
Personal tools
Categories