
Conditional Proxy Mod Initializers
Conditional Proxy Mod Initializers
This compact mod, consisting of just five classes, provides developers with a convenient tool for executing code depending on the presence of specific mods in the system.
One of the key features is that this mod always loads last in the queue. This completely eliminates the possibility of conflicts due to mod loading order and ensures stable operation.
It's important to note that all code and variables must be available before or during mod initialization stages. For example, executing code during datapack reload is not supported.
Usage Examples
Here's how you can use this mod in development practice:
// In main ModInitializer, ClientModInitializer, or any other class called during Fabric initialization
// For running a ModInitializer instance:
ConditionalModInitializer myConditionalModInitializer = new ConditionalModInitializer.Builder().mods("some-mod").initializer(SomeOtherInitializer.class).build();
// For executing arbitrary code:
ConditionalModInitializer myConditionalRunner = new ConditionalModInitializer.Builder().mods("some-other-mod").found(() -> {
// Code executes here
}).build();
public void onInitialize() {
ConditionalModInitializer.create().mods("some_mod").required_mods("some_other_dependency_mod").initializer(AnotherInitializer.class).build();
}
Important note: new ConditionalModInitializer.Builder() must be assigned to a variable or called inside a function. Static declaration (static{}) will not work!
Documentation
ConditionalModInitializer
create()
- returns a new Builder() instance (same as callingnew ConditionalModInitializer.Builder()
)mods()
- List: returns the list of mods required for this initializer to work required_mods()
- List: returns the list of all mandatory mods for this initializer can_run
- Boolean : shows whether the initializer has already been launchedenvironment()
- ExtendedEnvType : returns the environment (initializer type)ExtendedEnvType.CLIENT
: ClientModInitializerExtendedEnvType.SERVER
: ModInitializerExtendedEnvType.DEDICATED_SERVER
: DedicatedServerModInitializer
on_found()
- Runnable : returns the function to call when the required mod is found
ConditionalModInitializer.Builder
mods(String...)
: adds mods to the list that will trigger the initializer when presentrequired_mods(String...)
: adds mods to the list of mandatory dependenciesenvironment(ExtendedEnvType)
: sets the initializer environment (default:ExtendedEnvType.SERVER
: ModInitializer)found(Runnable)
: code to execute when the mod is foundinitializer(Class<ModInitializer>)
: initializer to run when the mod is foundmainInitializer(Class<ModInitializer>)
: main initializer to run when the mod is foundclientInitializer(Class<ClientModInitializer>)
: client initializer to run when the mod is foundserverInitializer(Class<DedicatedServerModInitializer>)
: server initializer to run when the mod is foundbuild()
: returns the finalized ConditionalModInitializer