
ClassJS
A KubeJS addon to create Java classes
Оцените первым
1.4K
1
1.4K
1
Список изменений
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.
Файлы
classjs-1.20.1-0.1-alpha.5.jar(200.33 KiB)
ОсновнойМетаданные
Канал релиза
Alpha
Номер версии
0.1-alpha.5
Загрузчики
Forge
Версии игры
1.20.1
Загрузок
108
Дата публикации
20.10.2025
