Mods Resource Packs Data Packs Plugins Shaders Modpacks
Get Modrinth App
Upgrade to Modrinth+
Sign in
ModsPluginsData PacksShadersResource PacksModpacks
Sign in
Settings

Conditional Proxy Mod Initializers

A simple library for running a proxy Fabric initializer if a required mod exists

218
1
Cursed
Library
Utility
AboutGalleryChangelogVersions

A simple 5-class mod which adds support for initializing code depending on if a specific mod exists.

This mod will always load last, so there is no need to worry about race conditions due to mod load order.

Code and variables must be available before or during any mod initialization stages (ie cannot be done on datapack reload for example)

Usage:


// Inside main ModInitializer, ClientModInitializer, or any class that gets called at some point during Fabric init

// For running an instance of a ModInitializer:
ConditionalModInitializer myConditionalModInitializer = new ConditionalModInitializer.Builder().mods("some-mod").initializer(SomeOtherInitializer.class).build();

// For running any unspecified code:

ConditionalModInitializer myConditionalRunner = new ConditionalModInitializer.Builder().mods("some-other-mod").found(() -> {
  // Code goes here
}).build();
    public void onInitialize() {
ConditionalModInitializer.create().mods("some_mod").required_mods("some_other_dependency_mod").initializer(AnotherInitializer.class).build();
}

  • NOTE: new ConditionalModInitializer.Builder() MUST be assigned to a variable, or be called inside a function to work! Static declaration ( static{} will NOT work!)

Docs:

  • ConditionalModInitializer

    • create() -> Returns a new Builder() instance. (Same as running new ConditionalModInitializer.Builder())
    • mods() -> List<String> : Returns the list of any mod that is required for this initializer
    • required_mods() -> List<String> : Returns list of all required mods for this initializer
    • can_run -> Boolean : Whether or not the initializer has ran yet
    • environment() -> ExtendedEnvType : Returns the environment (initializer type) for this initializer
      • ExtendedEnvType.CLIENT : ClientModInitializer
      • ExtendedEnvType.SERVER : ModInitializer
      • ExtendedEnvType.DEDICATED_SERVER: DedicatedServerModInitializer
    • on_found() -> Runnable : Returns the function to call when a required mod is found
  • ConditionalModInitializer.Builder

    • mods(String...) : Appends to the list of mods that will allow this initializer to run

    • required_mods(String...) : Appends to the list of required mods for this initializer

    • environment(ExtendedEnvType) : Sets the environment of the initializer (Default: ExtendedEnvType.SERVER : ModInitializer)

    • found(Runnable) : Code to execute if the mod is found

    • initializer(Class<ModInitializer>) : Initializer to run if the mod is found

    • mainInitializer(Class<ModInitializer>) : Initializer to run if the mod is found

    • clientInitializer(Class<ClientModInitializer>) : Initializer to run if the mod is found

    • serverInitializer(Class<DedicatedServerModInitializer>) : Initializer to run if the mod is found

    • build() : Returns the finalized ConditionalModInitializer

90% of ad revenue goes to creators

Support creators and Modrinth ad-free with Modrinth+

Compatibility

Minecraft: Java Edition

1.21
1.20.x
1.19.x
1.18.x
1.17.x
1.16.x
1.15.x
1.14.x

Platforms

Fabric

Supported environments

Server only
Singleplayer

Creators

Feintha
Feintha Member

Details

Licensed GPL-3.0-only
Published 11 months ago
Updated 11 months ago

Modrinth is open source.

main@9ed1dd7

© Rinth, Inc.

Company

TermsPrivacyRulesCareers

Resources

SupportBlogDocsStatus

Interact

Discord X (Twitter) Mastodon Crowdin
Get Modrinth App Settings
NOT AN OFFICIAL MINECRAFT SERVICE. NOT APPROVED BY OR ASSOCIATED WITH MOJANG OR MICROSOFT.