Mods/Creating mods/Starting your first mod

From Minecraft Wiki
Jump to: navigation, search
The contents of this page are not supported by Mojang AB, the Minecraft Wiki, the Minecraft IRC channel or the Minecraft Forums.
Clock.png
This article needs updating.
Description: ModLoader or directly modifying the base source are no longer recommended; forge (or liteloader or another loader) is preferred). Additionally, probably a lot of information is just using outdated techniques; this article needs a run-through to make sure everything is up-to-date.

In this tutorial, you will program your mod's primary file. The file you will create will have many purposes. It will identify all blocks, items, and/or entities you add, register all blocks and/or entities, load sprites and image files, generate blocks in the world, and much more. This tutorial requires that you have completely set up your MCP workspace with ModLoader and that you are using Eclipse IDE for Java Developers.

  1. To begin, click on "net.minecraft.src" in the Package Explorer (window to the left). Then, right click on "net.minecraft.src", hover over "New" and then click "Class". A window should pop up. In the "Name" box, type in "mod_myMod" (without quotation marks). You can replace "myMod" with the name of your mod if you would like, yet this tutorial will reference the file as "mod_myMod". You must keep the "mod_" part of it, or ModLoader may not load the mod. After typing the name, click "Finish". A new file should appear, containing the following:
package net.minecraft.src;

public class mod_myMod {

}
2. On the third line, press Enter to move the curly bracket ( { ) down to the next line. Go back to the end of the third line. Add the following to what is already there. extends BaseMod. This will tell the class to inherit constructors and methods from the BaseMod class. If you look on the left side of the code window, you will see a lightbulb with a red X. This means there is an error on that line. Do not worry, you will fix the error when following the next few steps.
3. Inside of the blank line, press Tab. Now, type public void load() {}.
4. Press Enter twice. Now, type the following:
public String getVersion()
{
	return "Version 1.0";
}
The above function (method) defines the version of your mod. Where it reads "Version 1.0", you may replace that with whatever version your mod is. Yet, players will not see what you put there (except in crash reports), so you can really put whatever you would like. Make sure whatever you type is still in the quotation marks, or you will receive errors.
5. The error should no longer be there. Instead, you may see a gray X icon. This means an error has been fixed on that line. To remove the icon, simply save by clicking "File" and then "Save All". The icon should be gone. Now, your primary mod file is complete. Read other tutorials below to begin adding content to your mod. Other tutorials will require that you already have typed the above codes.

Final Code[edit]

The following can be copied and pasted directly into your mod_myMod.java file. Replace "mod_myMod" with whatever you named the file.

package net.minecraft.src;

public class mod_myMod extends BaseMod
{	
	public void load() {}
	
	public String getVersion()
	{
		return "Version 1.0";
	}
}

A Pastebin of the above code can be found here.