Files
common/src/main/java/org/saturnclient/mod/mods/HealthDisplayMod.java
T
selimaj-devandclaude 33c09b6922 Describe every setting under its name
Properties can carry a one-line description, set with
NamedProperty.description for mods, a ConfigManager.property overload for
the client's config, and a helper in ModLayout. PropertyList rows show it
under the setting's name in muted text. Every mod, HUD layout, general,
UI style and animation setting now has one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-27 17:47:48 +02:00

93 lines
3.1 KiB
Java

package org.saturnclient.mod.mods;
import org.saturnclient.common.provider.Providers;
import org.saturnclient.config.property.BoolProperty;
import org.saturnclient.config.property.Property;
import org.saturnclient.config.property.SelectProperty;
import org.saturnclient.mod.HudMod;
import org.saturnclient.mod.Mod;
import org.saturnclient.mod.ModLayout;
import org.saturnclient.mod.ModSpec;
import org.saturnclient.ui.RenderScope;
import org.saturnclient.ui.resources.Fonts;
/**
* HealthDisplayMod renders the player's current health as a HUD
* element, with configurable display modes (raw health vs. hearts) and
* decimal precision.
*/
public class HealthDisplayMod extends Mod implements HudMod {
private static final BoolProperty enabled = Property.bool(false);
private static final SelectProperty displayMode = Property.select(0, "Health", "Hearts");
private static final SelectProperty decimals = Property.select(0, "0", "1", "2");
private static final ModLayout layout = new ModLayout(40, 18);
public HealthDisplayMod() {
super(
new ModSpec("Health Display", "health")
.description("Displays your current health")
.version("v0.2.0")
.tags("Utility")
.requires(Providers.feature::player),
enabled.named("Enabled"),
displayMode.named("Display mode").description("Show health points or hearts"),
decimals.named("Decimals").description("Decimal places shown"),
layout.prop());
}
// ---------------------------------------------------------------
// HudMod
// ---------------------------------------------------------------
@Override
public void renderHud(RenderScope scope) {
float health = Providers.feature.player().getHealth();
if (displayMode.value == 1)
health /= 2f; // convert to hearts
renderHealth(health, scope);
}
@Override
public void renderDummy(RenderScope scope) {
renderHealth(10f, scope);
}
// ---------------------------------------------------------------
// Rendering
// ---------------------------------------------------------------
private void renderHealth(float health, RenderScope scope) {
String fmt = switch (decimals.value) {
case 1 -> "%.1f ";
case 2 -> "%.2f ";
default -> "%.0f ";
};
String text = String.format(fmt, health);
scope.drawText(text, 0, 0, layout.font.value, layout.fgColor.value);
layout.width = Fonts.getWidth(text, layout.font.value);
layout.height = 18 * text.split("\n").length;
}
// ---------------------------------------------------------------
// Mod contract
// ---------------------------------------------------------------
@Override
public ModLayout getDimensions() {
return layout;
}
@Override
public boolean isEnabled() {
return enabled.value;
}
@Override
public void onEnabled(boolean e) {
enabled.value = e;
}
}