To create a gamerule, build and register it using the GameRuleBuilder of the Fabric API:
// Create and register a boolean gamerule, enabled by default private static final Identifier GAMERULE_IDENTIFIER = Identifier.of("custom_mod_name","gamerule_name"); public static final GameRule<Boolean> CUSTOM_BOOLEAN_GAMERULE = GameRuleBuilder .forBoolean(true) //default value declaration .category(GameRuleCategory.MISC) .buildAndRegister(GAMERULE_IDENTIFIER) ;
To get access to the value of a gamerule, use a server-world:
serverWorld.getGameRules().getValue(CUSTOM_GAMERULE);
The registered gamerule shows up untranslated in the gamerule list, which can be opened in the world creation screen. To translate the name, add an entry in the lang-file (see lang for more info):
{
"gamerule.custom_mod_name.gamerule_name": "Gamerule Name"
}