Proper Mod Structuring
The structure of your mod is important in keeping your mod organized, for both your benefit and the benefit of anyone who wishes to make a feature or an add-on for your mod. A disorganized mod structure may cause headaches when someone is trying to update it to a higher version, especially if they cannot modify the package structure, due to i.e. licensing.
Pick a unique package name for your mod. If you own a URL associated with your project, you can use it as your top level package. For example if you own "example.com", you may use
com.example as your top level package.
The next level package is usually your mod's ID: if your mod ID is
examplemod, your mod's package will be
Rather than clutter up a single class and package with everything, it is recommended you break your mod into subpackages. Below are a few possible methods for laying out your folder structure though you may as well come up with your own layout too.
- Group by Logic: One possible strategy is to make subpackages for logical units of your mod. For example, if you have a block called Super Furnace you would put its block, its block entity and its item all under
- Group by Function: Another common strategy is to make subpackages for grouping classes that have a common purpose. For example, your blocks classes can be under
blocks, your entities classes can be under
entities, your helper utilities can be under
No matter how your final structure looks like it is highly recommended to add a
client subpackage under your main package. This helps to isolate your client-only code from the rest, such as your Screens and renderers.
By keeping your code in clean subpackages, you can grow your mod much more organically.
Class Naming Schemes
A common class naming scheme allows easier deciphering of the purpose of the class, and makes it easier for someone developing for your mod to find specific classes.
The usual style is to use suffixes for your classes, for example:
PowerRingwould have a class name of
NotDirtwould have a class name of
BlockEntityfor a block called
SuperChewerwould have a class name of
The Mod File
The main mod class - the class that is annotated with
@Mod - is usually put into the main package of your mod, and not placed into a subpackage. This allows an easier time to access this, as your main mod class is the entrypoint of your mod.
@Mod annotation indicates to the mod loader that this class is the entry point of your mod. Each
@Mod annotation and their value should be paired with a mod id entry in your
mods.toml file is read by the mod loader to determine what mods are packaged into your JAR file, and what information to display to the user in the Mods listing screen (accessible by pressing the "Mods" button on the main menu of the game).
More information about the structure of this file and the possible configuration options available to you can be found on the dedicated page.