0.1-alpha.5
Compatibility
Required content
Changes
New Features
-
ClassCreator.createClassInitMethod-
createClassInitMethodcreates a<clinit>method, which is called to initialize the class.const ArrayList = Java.loadClass("java.util.ArrayList") let ExampleClass = ClassCreator.create("ExampleClass") .createField("listField", ArrayList) .toPublic().toStatic().toFinal() .build() .createClassInitMethod() .code(method => { method // Creates a new ArrayList .newAndConstructObject(ArrayList) // Put the created ArrayList into the `listField` static field. .putStaticField( ClassJSUtils.getCustomClassName("ExampleClass"), "listField", ArrayList ) .returnVoid(); }) .defineClass(); console.info(ExampleClass.listField); // Output in "startup.log": // [] [java.util.ArrayList] -
This is equivalent to the following Java code:
import java.util.ArrayList; public class ExampleClass { public static final ArrayList<Object> listField; static { listField = new ArrayList<>(); } } -
or:
import java.util.ArrayList; public class ExampleClass { public static final ArrayList<Object> listField = new ArrayList<>(); }
-
-
ClassCreator.createConstructor-
createClassInitMethodcreates a<init>method, that is, a constructor method.let ExampleClass = ClassCreator.create("ExampleClass") .createField("value", "int") .toPublic().toFinal() .build() .createConstructor(["int"]) .toPublic() .code(m => { // Standard way to call super constructor, // as Java expect every constructor of any class // to call a super constructor as the first operation. // (Should we add a new method to automate this process?) m.loadObject("this") .duplicate() .invokeSpecial("java.lang.Object", "<init>", [], "void") // Load the input integer .loadInt("arg0") // Put it into the field 'value' .putField(ClassJSUtils.getCustomClassName("ExampleClass"), "value", "int") .returnVoid(); }) .defineClass(); console.info(new ExampleClass(12345).value); // Output in "startup.log": // 12345.0 // (This is because KubeJS represents all numbers as doubles.) -
This is equivalent to the following Java code:
public class ExampleClass { public final int value; public ExampleClass(int arg0) { this.value = arg0; } }
-
Fixed Bug
- JSDoc for
FieldCreator.defaultNumericValueandFieldCreator.defaultStringValuesaid these methods were only forstatic finalfields. However, they can be used instatic, non-finalfields.
Optional dependencies
Projects on Modrinth are automatically available through a Maven repository for use with JVM build tools such as Gradle. To learn more about the Modrinth Maven API, click here.
Note: When available, you should use the creator's maven repo instead as it will have transitive dependency information that the Modrinth Maven API does not. You may also end up with duplicate dependencies if you use a mix of Modrinth and non-Modrinth Maven repositories for your dependencies, because the group identifier will be different when served through the Modrinth Maven API.
Maven coordinates:
Version ID:
build.gradle:
repositories {
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
}
}
// forRepositories(fg.repository) // Uncomment when using ForgeGradle
filter {
includeGroup "maven.modrinth"
}
}
}
// Standard Gradle dependency
dependencies {
implementation "maven.modrinth:AR7tLpwK:Mv6UReUt"
}
// Legacy Loom dependency
dependencies {
modImplementation "maven.modrinth:AR7tLpwK:Mv6UReUt"
}

