Modules

Creating a module

Every HUD element extends HudModule and implements its eight abstract methods. The quick start has the shortest version; this page adds what the base class does for you.

The minimum module

MyCustomModule.java
import com.eymistaken.simplecps.api.HudModule;
import com.eymistaken.simplecps.SimpleCPSConfig;
import net.minecraft.client.gui.GuiGraphicsExtractor;

public class MyCustomModule extends HudModule {

    @Override
    public String getName() {
        return "myaddon:tracker";
    }

    @Override
    public SimpleCPSConfig.Position getPositionType() {
        return SimpleCPSConfig.Position.TOP_LEFT; // default corner
    }

    @Override
    public int getXOffset() { return 0; }

    @Override
    public int getYOffset() { return 0; }

    @Override
    public boolean isEnabled() {
        return true; // tie to your own config
    }

    @Override
    public int getWidth() {
        return 100; // required for stacking
    }

    @Override
    public int getHeight() {
        return 20;
    }

    @Override
    public void extractRenderState(GuiGraphicsExtractor context, float tickDelta) {
        float scale = getScale() / 100f;
        context.pose().pushMatrix();
        context.pose().translate((float) this.x, (float) this.y);
        context.pose().scale(scale, scale);

        // After translating, draw relative to 0, 0, the local origin.
        drawText(context, "Hello World", 0, 0, 0xFFFFFFFF);

        context.pose().popMatrix();
    }

    @Override
    public void tick(net.minecraft.client.Minecraft client) {
        // Optional: runs every client tick, for timers, click tracking and so on.
        super.tick(client);
    }
}

Return a real size. Always return accurate values from getWidth() and getHeight(). Returning 0 removes the module from the stacking layout and makes it invisible.

Names must be unique. getName() keys your module's layout flags and its saved state, so a collision would silently corrupt both. registerModule() refuses a name that is already taken and logs an error instead of registering the module. Prefix yours with your mod id, such as "myaddon:tracker", and call manager.isNameTaken(String) first if you want to check yourself.

What you inherit

this.clientMinecraft.getInstance(), set for you.
this.x, this.yWhere the layout engine placed the module this frame.
tick(Minecraft)Called every client tick. A no-op by default.

Drawing text the player's way

Three inherited helpers make your module respect the player's appearance settings. Use them instead of drawing text directly.

void drawText(GuiGraphicsExtractor context, String text, int x, int y, int color)since 1.2.0

Draws in Minecraft's font, honoring the Text Outline setting and the current fade alpha. Since 1.2.5 it always uses the vanilla font.

int textWidth(String text)since 1.2.0

Measures a string exactly as drawText draws it.

int col(int argb)since 1.2.0

Applies the current fade alpha to any color, for anything you draw yourself.

Fading in and out

Modules opt into the smooth fade that plays when they appear or disappear by overriding supportsFade(). It defaults to false, and your module pops in and out. Return true only if every color you draw goes through col() or drawText(); otherwise your module stays fully opaque while the rest fades.

MyCustomModule.java
@Override
public boolean supportsFade() {
    return true;
}