MonitoringMinecraft MonitoringMinecraft

ClassJS

Мод Forge

A KubeJS addon to create Java classes

1к скачиваний 1 подписчик
Оцените первым

ClassJS is a mod to create Java classes in KubeJS.

Basic Example

You may operate Java byte code to build your own methods.

Note: Some instructions that interacts with classes (getstatic, invokestatic, new, etc.) is protected under KubeJS's class filters. You may not use them to access classes that is not allowed by KubeJS or its other addons. Neither can you extend or implement them.

let ExampleClass = ClassCreator.create("ExampleClass")
    .toPublic()           // Set the class to public
    .defaultConstructor() // Add a default constructor
    .createMethod("exampleMethod", [], "java.lang.String") // Method name, parameter types, and return type
        .toPublic()
        .code(builder => {
            builder.pushString("Hello, ClassJS!")   // Push a string reference to the operand stack
                .returnObject();                    // Returns the string
        })
    .defineClass();     // Define the class

console.info((new ExampleClass()).exampleMethod());

Equivalent Java code:

public class ExampleClass {

    public ExampleClass() {
        super();
    }

    public String exampleMethod() {
        return "Hello, ClassJS!";
    }

}

Code in JavaScript

If you do not want to learn Java byte code, you can create methods using JavaScript functions.

let ExampleClass = ClassCreator.create("ExampleClass")
    .toPublic()
    .createMethod("exampleMethod", ["int", "int"], "int")
        .toPublic().toStatic()
        .codeJS((num1, num2) => {
            return num1 + num2;
        })
    .defineClass();

console.info(ExampleClass.exampleMethod(1, 2));
// Output in startup.log
// 3.0

Equivalent Java code:

public ExampleClass {
    
    // Note: This class do not even have a constructor,
    //         as the JavaScript above did not call `defaultConstructor`,
    //         neither did it created any other constructors.

    public static int exampleMethod(int i1, int i2) {
        return i1 + i2;
    }

}

Load a Created Class

Classes can be only defined in startup scripts. If you want to use them in other scripts, you can use ClassJSUtils.loadClass method.

ClassCreator.create("SomeClass")
    /** Do some operations to add content to this class */
    .defineClass();

// In other scripts:

let SomeClass = ClassJSUtils.loadClass("SomeClass");
// Then you can use `SomeClass`
Смотри также

Похожие подборки моды — по версиям Майнкрафта, загрузчикам и жанрам.

Сервера Майнкрафт

Играть интереснее на сервере — выбирай в рейтинге серверов Майнкрафт и заходи прямо сейчас.

SkyBars
SkyBars Java + BE
585 онлайн
1.8 — 26.2 версия
🎮 ВЫЖИВАНИЕ ⚔️ АНАРХИЯ 🚗 ГТА РП 🎤 ГОЛОСОВОЙ ЧАТ 🎁 БЕСПЛАТНЫЙ ДОНАТ 🌟 СМП 💻 ПК+ТЕЛЕФОН
CLOUDWORLD
0 онлайн
1.16.5 — 1.21.11 версия
Пвп, Арены, Дуэли, Кейсы, донаты, /free, приваты, спавн,
Battle Mine
Battle Mine Java + BE
0 онлайн
1.21.4 — 26.2 версия
ОТКРЫТИЕ! 20 + различных ивентов, 10+ различных боссов, много интересных механник
MigosMc
MigosMc Java + BE
812 онлайн
1.8 — 26.2 версия
🌿 MigosMc.net | Гриферский сервер с войс-чатом | Награды за онлайн ⭐ ВЫЖИВАНИЕ⭐ ОДИНБЛОК⭐ МИНИ-ИГРЫ
MineLauncher
Лаунчер Майнкрафт без лицензии — все версии
Бесплатный лаунчер для ПК и Андроид — все версии 26.2, 1.21.11, 26.1.2, 1.21.8. Fabric, NeoForge, Forge, шейдеры, моды и скины в один клик.
Без лицензии Fabric, NeoForge, Forge Моды, шейдеры, скины Все версии Майнкрафта ПК и Андроид Для слабых ПК Сервера в лаунчере
Скачать бесплатно
Windows и Андроид · Бесплатно · Без лицензии
Наш чат