Wuppy’s Minecraft Forge Modding Tutorials for 1.7: Basic File Part 2: @Mod

In the Basic File Part 1 tutorial I explained the package and import lines from the ExampleMod. In this tutorial I will explain the @Mod line. The code from the file.

The lines we are going to look at in detail for this tutorial are these.

@Mod is perhaps the most important line of code in your mod. Without this line Forge doesn’t know about the existence of your mod and will not run any of the code. Except for making the mod work it also makes you set a few important things about the mod.

@Mod is an annotation in Java. If you want to know more about annotations you should read this. All you really require to know about that part is that it tells Forge this file is a mod. However, it is suggested to learn a bit about annotations, because a basic understanding of Java is very useful when modding Minecraft.

The @Mod part is followed by a bracket and then modid = ExampleMod.MODID. The modid piece is used to tell Forge the name of the mod and the ExampleMod.MODID is where it gets the name. Because the annotation is outside of the class, I’ll explain a bit about classes, methods and variables in the next tutorial, it requires you to write the class or file name followed by a dot and then the variable name in there. The variable is a public static final String called MODID which contains the word examplemod. In the next tutorial I will explain what all of the words mean, but for now all you should know is that it simply sends “examplemod” to Forge.

After the MODID there is a comma which separates the first from the second value. The second value is version. This version is also required by Forge and will be shown in game under the mods option. The code for the version is almost completely the same as the MODID part, but it accesses VERSION instead of MODID.

This line of code makes sure Forge knows this file is a mod and it also tells Forge the name, examplemod, and the version, 1.0.
In the next tutorial I will explain a bit more Java based on classes, keywords such as public, static, final and String.


For a more detailed explanation and much more, check out my book Sams Teach Yourself Mod Development for Minecraft in 24 Hours.

STY Minecraft Mod Development Book

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">