Skip to content

Creating a new module

DustinRepo edited this page Jun 9, 2022 · 10 revisions

Custom Categories

Jex supports adding custom categories with your plugins. To create a new category, make an instance of me.dustin.jex.feature.mod.core.Category using the name of the category, and the color you wish for it to display with. Creating a new instance automatically adds it to the list of categories. Example:

public static final Category EXAMPLE = new Category("Example", 0xff00ff00);

Creating a module

To create a new module, create a class that extends me.dustin.feature.mod.core.Feature

There are multiple constructors for many ways to set up a mod.

By default, only two values are needed in the constructor.

  1. Category: The category of the module
  2. Description: The description of the module

There are also optional values you can set

  1. Key: The keybind of the module. use GLFW.GLFW_KEY_key_name.
  2. Name: The name of the module. If not set, it will be automatically set to the name of the class
  3. Enabled: Whether or not the module is enabled by default
  4. Visible: Whether or not the module is visible by default

Your code should look something like this

import me.dustin.jex.feature.mod.core.Feature;
import org.lwjgl.glfw.GLFW;

public class ExampleFeature extends Feature {

    public ExampleFeature() {
        super(ExamplePlugin.EXAMPLE, "An example mod.");
    }

}

Adding Options

Jex's option system uses generic typing, allowing you to specify any underlying type for the option. Create a new me.dustin.jex.feature.property.Property instance using the PropertyBuilder class nested inside of that class.

You can also nest options inside of eachother, using the parent method in PropertyBuilder to specify a parent property, and optionally using depends method to decide when it should be visible in the gui

Here are some examples

import me.dustin.jex.feature.mod.core.Feature;
import me.dustin.jex.feature.option.annotate.Op;
import me.dustin.jex.feature.option.annotate.OpChild;
import org.lwjgl.glfw.GLFW;

public class ExampleFeature extends Feature {
    //Mode is an enum
    public final Property<Mode> exampleModeProperty = new Property.PropertyBuilder<Mode>(this.getClass())
            .name("Example Mode")
            .value(Mode.ONE)
            .build();

    public final Property<Color> exampleColorProperty = new Property.PropertyBuilder<Color>(this.getClass())
            .name("Example Color")
            .value(new Color(255, 0, 255))
            .build();

    public final Property<Boolean> exampleBooleanProperty = new Property.PropertyBuilder<Boolean>(this.getClass())
            .name("Example Boolean")
            .value(true)
            .build();

    public final Property<Double> exampleDouble = new Property.PropertyBuilder<Double>(this.getClass())
            .name("Example Double")
            .value(2.5)
            .min(1)
            .max(5)
            .inc(0.5f)
            .build();

    public final Property<Float> exampleFloat = new Property.PropertyBuilder<Float>(this.getClass())
            .name("Example Float")
            .value(2.5f)
            .max(5)
            .build();

    public final Property<Integer> exampleInt = new Property.PropertyBuilder<Integer>(this.getClass())
            .name("Example Int")
            .value(2)
            .max(5)
            .build();

    public final Property<Long> exampleLong = new Property.PropertyBuilder<Long>(this.getClass())
            .name("Example Long")
            .value(1000L)
            .min(500)
            .max(5000)
            .inc(500)
            .parent(exampleModeProperty)
            .depends(parent -> parent.value() == Mode.ONE)
            .build();

    public ExampleFeature() {
        super(ExamplePlugin.EXAMPLE, "An example mod.");
    }
}

Adding Events

To add events, you use the me.dustin.events.core.annotate.EventPointer above a me.dustin.events.core.EventListener field, using the event class as the type parameter. You can find all events here.

You can also use filters, to make the code cleaner for some events by only passing in a PRE event, or a packet event with a specific packet for example. You can find all filters here

Here is an example:

import me.dustin.events.core.EventListener;
import me.dustin.events.core.annotate.EventPointer;
import me.dustin.example.ExamplePlugin;
import me.dustin.example.gui.ExampleScreen;
import me.dustin.jex.event.filters.KeyPressFilter;
import me.dustin.jex.event.misc.EventJoinWorld;
import me.dustin.jex.event.misc.EventKeyPressed;
import me.dustin.jex.feature.mod.core.Feature;
import me.dustin.jex.feature.option.annotate.Op;
import me.dustin.jex.feature.option.annotate.OpChild;
import me.dustin.jex.helper.misc.Wrapper;
import org.lwjgl.glfw.GLFW;

public class ExampleFeature extends Feature {

    public final Property<Mode> exampleModeProperty = new Property.PropertyBuilder<Mode>(this.getClass())
            .name("Example Mode")
            .value(Mode.ONE)
            .build();

    public final Property<Color> exampleColorProperty = new Property.PropertyBuilder<Color>(this.getClass())
            .name("Example Color")
            .value(new Color(255, 0, 255))
            .build();

    public final Property<Boolean> exampleBooleanProperty = new Property.PropertyBuilder<Boolean>(this.getClass())
            .name("Example Boolean")
            .value(true)
            .build();

    public final Property<Double> exampleDouble = new Property.PropertyBuilder<Double>(this.getClass())
            .name("Example Double")
            .value(2.5)
            .min(1)
            .max(5)
            .inc(0.5f)
            .build();

    public final Property<Float> exampleFloat = new Property.PropertyBuilder<Float>(this.getClass())
            .name("Example Float")
            .value(2.5f)
            .max(5)
            .build();

    public final Property<Integer> exampleInt = new Property.PropertyBuilder<Integer>(this.getClass())
            .name("Example Int")
            .value(2)
            .max(5)
            .build();

    public final Property<Long> exampleLong = new Property.PropertyBuilder<Long>(this.getClass())
            .name("Example Long")
            .value(1000L)
            .min(500)
            .max(5000)
            .inc(500)
            .parent(exampleModeProperty)
            .depends(parent -> parent.value() == Mode.ONE)
            .build();

    public ExampleFeature() {
        super(ExamplePlugin.EXAMPLE, "An example mod.");
    }

    @EventPointer
    private final EventListener<EventJoinWorld> eventJoinWorldEventListener = new EventListener<>(eventJoinWorld -> {
        ExamplePlugin.getLogger().info("Hello world!");
    });

    @EventPointer
    private final EventListener<EventKeyPressed> eventKeyPressedEventListener = new EventListener<>(eventKeyPressed -> {
        Wrapper.INSTANCE.getMinecraft().setScreen(new ExampleScreen());
    }, new KeyPressFilter(EventKeyPressed.PressType.IN_GAME, GLFW.GLFW_KEY_P));
}

Clone this wiki locally