Package net.fabricmc.loader.api
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
:
Multiple keys can be present in the"languageAdapter": { "<a key>": "<the binary name of the language adapter class>" }
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 accepet 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 andtype
is assignable from the class.An example of an entrypoint class
You would declarepackage 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() {} }
"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, andtype
must be assignable from the field's class.An example of an entrypoint field
You would declarepackage 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() {} }
"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 implementtype
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
You would declarepackage 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() {} }
"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 oftype
from an arbitrary string declaration.
-
Method Details
-
create
Creates an object oftype
from an arbitrary string declaration.- Type Parameters:
T
- the type- Parameters:
mod
- the mod which the object is fromvalue
- the string declaration of the objecttype
- 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
-