Interface LanguageAdapter


public interface LanguageAdapter
Creates instances of objects from custom notations.

It enables obtaining of other JVM languages' objects with custom instantiation logic.

A language adapter is defined as so in fabric.mod.json:

"languageAdapter": { "<a key>": "<the binary name of the language adapter class>" }
Multiple keys can be present in the languageAdapter section.

In the declaration, the language adapter is referred by its binary name, such as "mypackage.MyClass$Inner". It must have a no-argument public constructor for the Loader to instantiate.

The default language adapter from Fabric Loader can accept value as follows:

  • A fully qualified reference to a class, in binary name, such as package.MyClass$Inner, where the class has a public no-argument constructor and type is assignable from the class.

    An example of an entrypoint class

    package net.fabricmc.example; import net.fabricmc.api.ModInitializer; public class ExampleMod implements ModInitializer { public ExampleMod() {} // the constructor must be public no-argument @Override public void onInitialize() {} }
    You would declare "net.fabricmc.example.ExampleMod".

    For each entrypoint reference, a new instance of the class is created. If this class implements two separate entrypoints, there will be two distinct instances of this class in two entrypoint containers.

  • A fully qualified reference to a class in binary name followed by :: and a field name. The field must be static, and type must be assignable from the field's class.

    An example of an entrypoint field

    package net.fabricmc.example; import net.fabricmc.api.ModInitializer; public final class ExampleMod implements ModInitializer { public static final ExampleMod INSTANCE = new ExampleMod(); private ExampleMod() {} // Doesn't need to be instantiable by loader @Override public void onInitialize() {} }
    You would declare "net.fabricmc.example.ExampleMod::INSTANCE".

  • A fully qualified reference to a class in binary name followed by :: and a method name. The method must be capable to implement type as a method reference. If the method is not static, the class must have an accessible no-argument constructor for the Loader to create an instance.

    An example of an entrypoint method

    package net.fabricmc.example; public final class ExampleMod { private ExampleMod() {} // doesn't need to be instantiable by others if method is static public static void init() {} }
    You would declare "net.fabricmc.example.ExampleMod::init".

  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    create(ModContainer mod, String value, Class<T> type)
    Creates an object of type from an arbitrary string declaration.
    Get an instance of the default language adapter.
  • Method Details

    • getDefault

      static LanguageAdapter getDefault()
      Get an instance of the default language adapter.
    • create

      <T> T create(ModContainer mod, String value, Class<T> type) throws LanguageAdapterException
      Creates an object of type from an arbitrary string declaration.
      Type Parameters:
      T - the type
      Parameters:
      mod - the mod which the object is from
      value - the string declaration of the object
      type - the type that the created object must be an instance of
      Returns:
      the created object
      Throws:
      LanguageAdapterException - if a problem arises during creation, such as an invalid declaration