Build and test a Minecraft mod
How to build a Fabric, NeoForge or Forge mod in Modsmith, run it in a test client or dedicated server, apply changes to the running game and debug it. This guide assumes a project created as in Getting started.
Build the mod
Press Build in the toolbar, next to the launch button. Modsmith runs the project's own Gradle wrapper with a suitable JDK. While it runs, the button reads Building; click it to see the output in the Tasks panel. Compile errors are listed in Problems and link to the line in the editor. The arrow next to Build also offers Clean build and Run data generation.
When the build finishes, the Build menu opens and lists the JARs from build/libs. The mod JAR comes first; that is the file to share or upload.
- Save a copy saves the JAR wherever you choose.
- Show in folder opens the folder that contains it.
Source and development JARs are listed below the mod JAR. You do not need to build before launching: launching builds what it needs.
Set the mod's name, version and dependencies
Open Project in the left rail. The page shows the mod's details: display name, version, group, authors, license, homepage, issue tracker and description. It also lists the dependencies the mod declares to the loader, with their version ranges and whether each one is required.
Edit them and press Save changes. Modsmith writes each value to the file where the project keeps it (gradle.properties, fabric.mod.json or mods.toml), and the next build uses it. To edit those files directly instead, open them with the buttons at the top of the page. In a mod with several targets, the page edits the files in the folder of the target selected in the toolbar, such as forge-1.20.1.
Publish to Modrinth and CurseForge
Under Publishing in Project settings, link the mod to its Modrinth project (paste its slug or link) and its CurseForge project (the Project ID from the About Project box). Then add an upload token for each site:
- Modrinth: a personal access token with the Create versions scope, from your Modrinth settings.
- CurseForge: an API token from the CurseForge authors settings.
Tokens are kept in your system's secret store, never in the project.
After a build, open the Build menu and press the publish button on the mod JAR. Check the version number, release type, Minecraft versions and changelog, then press Publish. Each site gets the JAR as a new version, and the dialog links to it when it is done.
Search and replace
Press Ctrl+Shift+F, or Search in the rail, to search every file in the project.
- The buttons in the search box turn on match case, whole word and regular expressions.
- The file filters limit the search to paths such as
*.javaorsrc/main/resources. - Click a result to open the file at that match.
- To replace, open the replace box with the arrow on the left or Ctrl+Shift+H. You can replace one match, one file or all results.
Inside a single file, Ctrl+F finds text and Ctrl+H replaces it.
Run configurations
Projects created with the test profiles starter have two run configurations, chosen in the list at the left of the toolbar:
- Test Client runs the project's current code in a Minecraft client.
- Dedicated Server checks that the project works on a dedicated server, where client-only code must not run.
Each configuration has its own game folder under .modsmith/instances, with its own mods, options and worlds, so test worlds never mix with your normal Minecraft installation. The Configs page (Run configurations) lets you change memory, Java, JVM and game arguments, turn the development bridge on or off, test the built release JAR instead of the development setup, or duplicate a configuration.
Launch the game
- Choose Test Client and press Launch client. The toolbar shows Building, then Starting.
- The Client tab shows the game. On Windows, and on Linux with X11 or XWayland, it is embedded in the tab; Move to a separate window releases it, and Embed here brings it back. Click the game to type into it and press Esc in the game to release the mouse.
- Press Stop when you are done. The game is asked to close normally, so the world is saved.
For the Dedicated Server, Modsmith asks you to accept the Minecraft EULA once for that server, then starts it. The Console shows its output and has an input line for server commands.
Apply changes without restarting
While the game runs, Apply changes in the toolbar lists what you edited since launch:
- Code compiles the project and hot-reloads changed Java method bodies. It needs Hot reload and debugger turned on for the configuration; if it is off, Turn on and restart does that for you.
- Assets reloads textures, models, sounds and translations.
- Game data reloads recipes, tags, loot tables and advancements.
Some changes cannot be applied to a running JVM, such as adding or removing fields or methods, or changing mixins. Modsmith lists the reasons, changes nothing in the game, and offers to restart. See Java hot reload for the full list.
Debug with breakpoints
- Turn on Hot reload and debugger for the configuration on the Configs page, and launch it.
- Open a Java file and click in the gutter to the left of the line numbers to set a breakpoint.
- Press the debug button in the toolbar to open the Debug panel, then Start debugging. The first time, Modsmith downloads the Java debugger (about 3 MB) and restarts Java support.
- When the game reaches the breakpoint, the panel shows the call stack and variables, and Evaluate runs expressions such as
player.getName(). Use F5 to continue, F10 to step over, F11 to step into and Shift+F11 to step out. - Stop debugging detaches and leaves the game running.
The debug port accepts one connection at a time, so stop debugging before using Apply changes for code.
Inspect the running game
With the development bridge on (it is part of the starter test configurations and is never included in your release JAR), the Inspector shows the block or entity you are looking at, with quick actions to give items and run commands, and the Client tab can take screenshots of the game.
Automate checks
- Scenarios (Tests, scenarios) run scripted steps against a running game: commands, giving items, and checks on blocks, inventories, registry entries and log lines. New scenario opens a visual editor, and steps can be filled in from the game. When the game is not running, Run starts the configuration in a fresh test world and stops it afterwards; against a running game it runs in place. Scenarios can also name a server and players for multiplayer checks.
- Multiplayer test… in More actions starts the dedicated server and up to four clients with separate player names, already connected.
- Performance (Tests, performance) benchmarks a configuration on a fresh world and compares two results.
Common problems
- Gradle fails before compiling. Usually a Java version mismatch; see Java problems.
- Launch client is greyed out. The project's loader is not supported for launching, or a build is already running.
- Apply changes says the game must restart. The change altered a class's structure; restart with Rebuild and restart.
More fixes are in Troubleshooting.