Quilt Loader 1
Loading...
Searching...
No Matches
org.quiltmc.loader.api.LanguageAdapter Interface Reference

Creates instances of objects from custom notations. More...

Inheritance diagram for org.quiltmc.loader.api.LanguageAdapter:
net.fabricmc.loader.api.LanguageAdapter org.quiltmc.loader.impl.util.DefaultLanguageAdapter net.fabricmc.loader.impl.util.DefaultLanguageAdapter net.fabricmc.loader.util.DefaultLanguageAdapter

Public Member Functions

< T > T create (ModContainer mod, String value, Class< T > type) throws LanguageAdapterException
 Creates an object of type from an arbitrary string declaration.

Static Public Member Functions

static LanguageAdapter getDefault ()
 Returns the default language adapter.

Detailed Description

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": { "&lt;a key&gt;": "&lt;the binary name of the language adapter class&gt;" }

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".

Member Function Documentation

◆ create()

< T > T org.quiltmc.loader.api.LanguageAdapter.create ( ModContainer mod,
String value,
Class< T > type ) throws LanguageAdapterException

Creates an object of type from an arbitrary string declaration.

Parameters
modthe mod which the object is from
valuethe string declaration of the object
typethe type that the created object must be an instance of
<T>the type
Returns
the created object
Exceptions
LanguageAdapterExceptionif a problem arises during creation, such as an invalid declaration

◆ getDefault()

LanguageAdapter org.quiltmc.loader.api.LanguageAdapter.getDefault ( )
inlinestatic

Returns the default language adapter.

Most mods will have no use for this method - instead it is intended for other LanguageAdapters to fallback to the default behaviour.

Returns
The default language adapter.

Implemented in net.fabricmc.loader.api.LanguageAdapter.


The documentation for this interface was generated from the following file:
  • src/main/java/org/quiltmc/loader/api/LanguageAdapter.java