Mod Configuration

Configuration Using TOML

A simple and readable way to manage mod settings is by using TOML files. This format allows you to organize settings into categories and entries, with comments that make it easier to read and edit manually.

Example in Java:

public static final String MOD_ID = "modid";
public static TomlConfigHandler CFG;
private static final Toml TOML = new Toml("A comment");  // General comment for the TOML file

// Add a category called "IDs" with two entries
TOML.addCategory("IDs")
    .addEntry("starting_item_id", 19000)
    .addEntry("starting_block_id", 11000);

// Initialize the config handler with the MOD_ID and the TOML configuration
CFG = new TomlConfigHandler(MOD_ID, TOML);

Generated .toml output:

# A comment

[IDs] # Category
    starting_item_id = 19000 # Values
    starting_block_id = 11000

Retrieving values in code

You can read values using getters matching the data type:

Example to get an integer value:

int value = CFG.getInt("CategoryName.value_name");

Using Gamerules in Minecraft

Why use gamerules?

Gamerules provide a simple, accessible way to add configurable options that players can change directly in-game. They have several advantages:

Creating a custom gamerule

Minecraft provides different gamerule types in the package net.minecraft.core.data.gamerule.

For example, to create a boolean gamerule:

public static GameRuleBoolean MY_GAMERULE = null;

static {
    // Register the gamerule with a unique name and a default value (true here)
    MY_GAMERULE = GameRules.register(new GameRuleBoolean("myGameruleName", true));
}

Types of gamerules available

Types