Appearance
Modules
A module is one feature: it has a switch in the mod menu, an optional hotkey and its own settings. HUD widgets are modules too.
java
public final class AutoGreeting extends Module<AutoGreeting.Config> {
public static final class Config extends ModuleConfig {
@Text(maxLength = 40)
public final ConfigProperty<String> message = ConfigProperty.of("Hello!");
Config() {
super(false); // off by default
}
}
public AutoGreeting() {
super("my_addon_greeting", Category.UTILITY, new Config());
}
@Override
protected void onEnable() { /* switched on (also at start when it is on) */ }
@Override
protected void onDisable() { /* switched off */ }
}Register it in your entry point: lynx.modules().register(new AutoGreeting()).
Ids
The id is used for the settings file, the translations and server rules. It must match [a-z0-9_]{2,40} and be unique across all addons, so prefix it with your addon name (my_addon_…).
Category
Where the module appears in the mod menu: HUD, PVP, VISUAL, UTILITY, PERFORMANCE, SERVER. HUD widgets are always HUD.
Switch and hotkey
Every ModuleConfig has two settings already:
enabled: the switch. Servers will be able to turn modules off with it.toggleKey: a key or mouse button that switches the module in game. Empty by default; the player sets it.
Read the state with isEnabled(). Set it from code with config().enabled.set(true).
Events only while enabled
While a module is enabled, LynxClient registers it on the event bus. So its @Subscribe methods only run when the player turned it on. No need to check isEnabled() in every listener. See Events.
More hooks
| Method | Use |
|---|---|
isToggleable() | Return false for modules that are always on (no switch in the menu) |
isSettingVisible(String key) | Hide a setting, e.g. one that makes no sense on this Minecraft version |