public interface LanguageAdapter
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:
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
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.
:: 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
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".
:: 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
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".
| Modifier and Type | Method and Description |
|---|---|
<T> T |
create(ModContainer mod,
String value,
Class<T> type)
Creates an object of
type from an arbitrary string declaration. |
<T> T create(ModContainer mod, String value, Class<T> type) throws LanguageAdapterException
type from an arbitrary string declaration.T - the typemod - the mod which the object is fromvalue - the string declaration of the objecttype - the type that the created object must be an instance ofLanguageAdapterException - if a problem arises during creation, such as an invalid declaration