Annotations
Annotations are a powerful and useful thing in Java which Forge and FML takes advantage of to create an easier modding environment for us to work with. In this section you will learn the basic and fundamental annotations which Forge and FML use.
@Mod - This annotation tells Forge that the class this annotates is a the base class for your Mod. This has a few different parameters, however there is only three parameters you need to add to have a fully functional mod:
@NetworkMod - This annotation tells Forge what to do with the mod when it has multiplayer compatibility. This annotation has quite a lot of parameters, but so few are actually required, note that if your getting into a big mod you may need set custom packet handlers, we will have tutorials on this later on! These are the required parameters:
@SidedProxy - This is used to create proxies on either side, determined by the parameters added, these are the parameters:
@PreInit - The method this annotates is called before the initialization of the game. Configs and other important things go here.
@Init - The method this annotates is called during the initialization of the game. Most of the mod code, such as item and block registers, recipe registers and naming goes in here.
@PostInit - The method this annotates is called after the initialization of the game. Some cross-mod-compatibility things go here, however this may be too early for other cross-mod-compatibility things.
@Instance - This annotation is used by Forge to create and provide an instance of the mod class that is unique to your mod.
@Mod - This annotation tells Forge that the class this annotates is a the base class for your Mod. This has a few different parameters, however there is only three parameters you need to add to have a fully functional mod:
- modid (String): This parameter gives a unique mod identifier to Forge. This is used behind-the-scenes in the code to determine which proxy is for what mod, which Init annotation belongs to what mod, etc.
- name (String): This parameter adds a unique name to your mod, this name is hwat is used in the mods menu and is what any Logger that is a child of the FML Logger uses to determine the name of the Logger.
- version (String): This parameters adds a version number to your mod. Servers can use this to see which version of what mod each player has, and if the players version doesn't match the servers mods versionbounds, it kicks the player saying that they need an up-to-date mod to play.
@NetworkMod - This annotation tells Forge what to do with the mod when it has multiplayer compatibility. This annotation has quite a lot of parameters, but so few are actually required, note that if your getting into a big mod you may need set custom packet handlers, we will have tutorials on this later on! These are the required parameters:
- clientSideRequired (boolean): Does the mod need the client side when playing on a server? Recommended: true.
- serverSideRequired (boolean): Does the mod need the server side when playing on the client? Recommended: false.
- versionBounds (String): The version that the client needs to play on a server.
@SidedProxy - This is used to create proxies on either side, determined by the parameters added, these are the parameters:
- clientSide (String): Class path of the mod's ClientProxy.
- serverSide (String): Class path of the mod's CommonProxy.
@PreInit - The method this annotates is called before the initialization of the game. Configs and other important things go here.
@Init - The method this annotates is called during the initialization of the game. Most of the mod code, such as item and block registers, recipe registers and naming goes in here.
@PostInit - The method this annotates is called after the initialization of the game. Some cross-mod-compatibility things go here, however this may be too early for other cross-mod-compatibility things.
@Instance - This annotation is used by Forge to create and provide an instance of the mod class that is unique to your mod.