Reference

HudModule

The base class every module extends. Eight methods are abstract; everything else has a default, so an addon built against an older release keeps running on a newer one.

public abstract class HudModule implements IHudElement, in com.eymistaken.simplecps.api.

Abstract methods

String getName()since 1.1.0

Unique key for your layout flags and saved state. Prefix it with your mod id.

SimpleCPSConfig.Position getPositionType()since 1.1.0

The anchor: one of the four corners, which stack automatically, or CENTER, which is centered rather than stacked.

int getXOffset()
int getYOffset()
since 1.1.0

Offset from the anchor in pixels. Any non-zero offset takes the module out of auto-stacking.

boolean isEnabled()since 1.1.0

Whether the module renders at all. Tie it to your own config.

int getWidth()
int getHeight()
since 1.1.0

The size of what you draw, with scale applied. Used by stacking, the editor and the preview card. Returning 0 takes the module out of the layout.

void extractRenderState(GuiGraphicsExtractor context, float tickDelta)since 1.1.0

Draw here. Translate to this.x and this.y, then draw from the local origin.

Fields

protected final Minecraft clientsince 1.1.0

Minecraft.getInstance(), set in the constructor.

protected int x
protected int y
since 1.1.0

Where the layout engine placed the module this frame. Translate to them before drawing.

protected float renderAlphasince 1.2.0

The opacity to draw with, from 0 to 1, set every frame while the module fades. Read it through col() rather than directly.

Placement and the editor

void setPositionType(SimpleCPSConfig.Position pos)since 1.1.0

Called when the player picks an anchor. A no-op by default; store the value in your own config.

void setXOffset(int x)
void setYOffset(int y)
since 1.1.0

Called as the editor moves the module, once a frame during a drag or a snap. No-ops by default.

int getScale()
void setScale(int scale)
since 1.1.0

The scale in percent. getScale() returns 100 and setScale() does nothing by default.

void resetToDefaults()since 1.1.0

What Reset Position does: put back the anchor, the offsets and the scale. A no-op by default.

void onPositionUpdated()since 1.2.0

Called after a drag is released, after an arrow-key nudge, and after the align and distribute tools move the module. The default saves simplecps.json.

List<IHudElement> getSubElements()since 1.2.0

Parts the editor drags on their own. Empty by default, which keeps the module one element. See Sub-elements.

int getLayoutWidth()
int getLayoutHeight()
since 1.2.0

The room the layout reserves when stacking. Defaults to getWidth() and getHeight(); return more to keep space while the module shows less, so its neighbors do not jump. Reach reserves room for "3.00 blocks" this way.

int getX()
int getY()
since 1.2.0

The render position, x and y, as the editor reads it.

void setRenderPosition(int x, int y)since 1.1.0

Sets x and y. Called by the layout engine; modules rarely need it.

Settings

List<HudModuleSetting> getContextMenuSettings()since 1.1.0

Rows for the editor's right-click menu, also shown on the settings page. By default a single Reset Settings action that calls resetVisualDefaults() and saves.

void resetVisualDefaults()since 1.1.0

What Reset Settings does. Reset colors and behavior; leave the enabled state and the offsets alone. A no-op by default.

List<HudModuleSetting> getSettingsScreenSettings()since 1.2.0

Rows shown only on the settings page, after the context-menu rows. Empty by default.

List<SettingsTab> getSettingsTabs()since 1.2.0

Tabs for the settings page. Empty by default, which gives one flat SETTINGS tab. See Your own tabs.

HudPreview getPreview()since 1.2.0

A live sample of the module for the settings screen's PREVIEW card. Returns null by default, which means no card at all.

final boolean isPreviewing()since 1.2.0

True while the module is drawn or measured as a preview rather than on the real HUD, measurement included.

final void setPreviewing(boolean previewing)since 1.2.0

Marks a preview pass. The settings screen calls it; modules only read the flag.

Drawing and ticking

void tick(Minecraft client)since 1.1.0

Called every client tick. A no-op by default.

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

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

protected int textWidth(String text)since 1.2.0

The width of text as drawText draws it.

protected int col(int argb)since 1.2.0

Applies the current fade alpha to a color.

boolean supportsFade()since 1.2.0

Whether the module fades in and out. false by default, which pops it in and out; return true only if every color goes through col() or drawText().

void setRenderAlpha(float alpha)since 1.2.0

Sets renderAlpha. Called by HudModuleManager every frame.

protected int getRainbowColor()since 1.1.0

The next rainbow color as ARGB, advancing half a degree of hue per call. Previews keep a phase of their own, so the live rainbow does not speed up while the menu is open.

Saved state

JsonElement saveState()since 1.2.0

Your settings, serialized, so they travel with presets, share codes and server configs. Returns null by default, which stores nothing. See Plugin state.

void loadState(JsonElement state)since 1.2.0

Restores what saveState() produced. Never called with null. A no-op by default.