Skip to content

Modules Core

Benjamin K edited this page Nov 3, 2021 · 2 revisions

The core module for Compound, this module must be included in your project for any other Compound module to function properly.

Core provides small utility methods and data structures that are common across more than one Compound module.

At the time of writing the main feature of the core module is to assist with reflection, providing two classes that allow you to reference private fields or methods on an existing class. Instead of storing references to the Field or Method using Java's reflection API you instead create an instance of Compound's WrappedField or WrappedMethod. You can find a member by providing its name and optionally any aliases that it may fall under during runtime.

As an example, in the CompoundContainer class of the UI module the position of slots needs to be adjusted. Unfortunately this field is not accessible directly, so a WrappedField is used to interact with this value.

First the WrappedFields are defined:

    private static final WrappedField<Integer> SLOT_X = WrappedField.create(Slot.class, "x", "field_75223_e");
    private static final WrappedField<Integer> SLOT_Y = WrappedField.create(Slot.class, "y", "field_75221_f");

Then the values can be modified:

    @Override
    protected Slot addSlot(Slot slot) {
        Slot out = super.addSlot(slot);
        SLOT_X.set(out, Integer.MIN_VALUE + (out.index * 16));
        SLOT_Y.set(out, Integer.MIN_VALUE);
        return out;
    }

Clone this wiki locally