Download Conditional Proxy Mod Initializers — Minecraft Mods — MetaMods
Conditional Proxy Mod Initializers

Conditional Proxy Mod Initializers

Active

Downloads

0

Last update

1 year ago

Versions

1.14 — 1.21
Client and server
Fabric
Libraries
Utils

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 calling new 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 launched
  • environment() - ExtendedEnvType : returns the environment (initializer type)
    • ExtendedEnvType.CLIENT : ClientModInitializer
    • ExtendedEnvType.SERVER : ModInitializer
    • ExtendedEnvType.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 present
  • required_mods(String...) : adds mods to the list of mandatory dependencies
  • environment(ExtendedEnvType) : sets the initializer environment (default: ExtendedEnvType.SERVER : ModInitializer)
  • found(Runnable) : code to execute when the mod is found
  • initializer(Class<ModInitializer>) : initializer to run when the mod is found
  • mainInitializer(Class<ModInitializer>) : main initializer to run when the mod is found
  • clientInitializer(Class<ClientModInitializer>) : client initializer to run when the mod is found
  • serverInitializer(Class<DedicatedServerModInitializer>) : server initializer to run when the mod is found
  • build() : returns the finalized ConditionalModInitializer
Project members
Feintha

Feintha

Developer

Created: 10 Jul 2024

ID: 24833