Package me.hackware.api.hud
Class HUDElement
java.lang.Object
me.hackware.api.hud.HUDElement
- All Implemented Interfaces:
SettingContainer
- Direct Known Subclasses:
TextHUDElement,VanillaHUDElement
Base class for draggable HUD elements.
Position is stored as an anchor (which 3×3 grid section) plus an offset
relative to that section's corner, so elements survive screen-size changes.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enumstatic enumstatic enumstatic final recordstatic enumOptional visibility keybind: toggles or holds the element visible/hidden. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected final Stringstatic final floatstatic final floatprotected intprotected intCurrent screen-space position (computed from anchor + offset each frame).protected intCurrent screen-space position (computed from anchor + offset each frame). -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedHUDElement(String id, int defaultX, int defaultY) protectedHUDElement(String id, int defaultX, int defaultY, HUDElement.Anchor defaultAnchor) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCondition(HUDElement.VisibilityCondition condition) protected voidaddSettings(Setting<?>... arr) Registers multiple settings at once.protected <S extends Setting<?>>
SaddSettings(S setting) Registers a setting with this element and returns it (modules pattern).booleanbooleanWhether this element supports the "Reset to default" context-menu action.voidclamp(int screenWidth, int screenHeight) Clamp position to screen bounds, respecting screen margin and per-side flags.voidvoidRemove saved position keys (for elements whose position is determined by a list).booleancontains(double mx, double my) protected static intGlobal default HUD text color (the HUD module's "Text Color" setting).intVisual (scaled) height — the logicalheightmultiplied byeffRenderScale().floatThe element's effective render scale (how much its logical size is multiplied to get the visual size).inteffWidth()Visual (scaled) width — the logicalwidthmultiplied byeffRenderScale().floatintgetId()intintMinimum bounding-box size this element reserves on its parent runtime list/group, even whenareConditionsMet()returns false and the element is otherwise collapsed.floatgetScale()intintgetWidth()intgetX()intgetY()floatThe element's per-element scale combined with the base HUD text scale — the total size multiplier an individually-scaleable graphical element should render at.static floathudScale()Base coordinate scale for the HUD.booleanWhether the editor may move this element.booleanbooleanprotected voidApply persisted values to every registered setting (call after declaring them).protected voidmigrateArgbColorKey(String legacyKey, String olderHexKey, String colorPath, String opacityPath) Legacy int-ARGB color (or an even older RGB-hex fallback key) → a ColorSetting {hex} map plus a separate 0–255 opacity value.protected voidmigrateColorSettingKey(String legacyColorKey, String legacyEnabledKey, String newPath) Key rename onto aColorSettingpath: legacy int-ARGB / hex-string colors become the ColorSetting map form, with an optional separate legacy enabled-boolean merged in (null= none).protected voidmigrateEnumSettingKey(String legacyKey, String newPath) Key rename with enum-value normalization (any legacy spelling → UPPER_SNAKE).protected voidmigrateOpacityIntoColorAlpha(String colorPath, String opacityPath, int defaultRgb) Standalone opacity setting → its color's own alpha channel, for elements that moved from "color + opacity" to a single alpha-enabled ColorSetting.protected voidmigrateOverrideColorKey(String legacyColorKey, String newPath) Nullable-override color migration: the legacy key existing at all meant "the user set a custom color", so the toggleable ColorSetting loads enabled.protected voidmigrateSettingKey(String legacyKey, String newPath) One-time key rename for the settings-definers migration: moves a legacyhud.<id>.<legacyKey>value onto the new slug path, verbatim.protected voidmigrateSettingKey(String legacyKey, String newPath, UnaryOperator<Object> convert) voidremoveCondition(int index) voidrender(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.client.gui.Font font) voidrender(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.client.gui.Font font, float textScale) protected abstract voidrenderContent(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.client.gui.Font font) voidrenderEditor(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.client.gui.Font font) voidrenderEditor(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.client.gui.Font font, float textScale) voidvoidRestore the constructor-supplied default anchor + offsets and persist them.voidresolve(int screenW, int screenH) Resolve absolute x,y from the saved anchor + offset for the current screen size.resolvedExpandX(int screenW) Resolve the effective expand anchor for an axis, handling AUTO by inferring from the element's screen position.resolvedExpandY(int screenH) voidresolveEditor(int screenW, int screenH) Editor-context resolve: same anchor math asresolve(int, int), but sized viaupdateEditorSize(net.minecraft.client.gui.Font)so elements whose live size depends on game state (target info collapses to 0×0 with no target, etc.) resolve at the size the editor displays and saves them with — otherwise their position would depend on whatever happened to be on screen at that moment.voidvoidPersist this element's settings after a value change (SettingContainer).voidsavePosition(int screenW, int screenH) voidbooleanWhether this element scales with the global HUD text scale.voidsetClampSides(boolean left, boolean right, boolean top, boolean bottom) voidsetEditorAlpha(float alpha) voidvoidvoidvoidsetPosition(int x, int y) voidsetScale(float v) Set the per-element scale, snapping to the same GUI-scale-aware fraction stops as the Client tab.voidsetVisibilityHoldShows(boolean holdShows) voidsetVisibilityKey(int key) voidvoidsnapshotAnchor(int screenW, int screenH) Snapshot the current absolute position into anchor + offset for the given screen size.voidupdateEditorSize(net.minecraft.client.gui.Font font) Update width/height as the editor would see them (with placeholder content).protected abstract voidupdateSize(net.minecraft.client.gui.Font font) booleanWhether the editor should auto-add a generic "Scale" slider bound togetScale()/setScale(float).floatScale to pass to the sharedrender(net.minecraft.client.gui.GuiGraphics, net.minecraft.client.gui.Font)wrapper.
-
Field Details
-
id
-
x
protected int xCurrent screen-space position (computed from anchor + offset each frame). -
y
protected int yCurrent screen-space position (computed from anchor + offset each frame). -
width
protected int width -
height
protected int height -
SCALE_MIN
public static final float SCALE_MIN- See Also:
-
SCALE_MAX
public static final float SCALE_MAX- See Also:
-
-
Constructor Details
-
HUDElement
-
HUDElement
-
-
Method Details
-
hudScale
public static float hudScale()Base coordinate scale for the HUD. HUD elements render in Minecraft's already gui-scaled space, so the Minecraft GUI scale is the base and this returns1.0. The user-facing HUD size multiplier is applied separately viaHudServices.getTextScale(). -
defaultTextColor
protected static int defaultTextColor()Global default HUD text color (the HUD module's "Text Color" setting). Elements draw with this wherever no per-element color override applies. -
addSettings
Registers a setting with this element and returns it (modules pattern). -
addSettings
Registers multiple settings at once. -
getSettings
-
loadElementSettings
protected void loadElementSettings()Apply persisted values to every registered setting (call after declaring them). -
saveContainerSettings
public void saveContainerSettings()Persist this element's settings after a value change (SettingContainer).- Specified by:
saveContainerSettingsin interfaceSettingContainer
-
migrateSettingKey
One-time key rename for the settings-definers migration: moves a legacyhud.<id>.<legacyKey>value onto the new slug path, verbatim. -
migrateEnumSettingKey
Key rename with enum-value normalization (any legacy spelling → UPPER_SNAKE). -
migrateSettingKey
-
migrateColorSettingKey
protected void migrateColorSettingKey(String legacyColorKey, String legacyEnabledKey, String newPath) Key rename onto aColorSettingpath: legacy int-ARGB / hex-string colors become the ColorSetting map form, with an optional separate legacy enabled-boolean merged in (null= none). -
migrateArgbColorKey
protected void migrateArgbColorKey(String legacyKey, String olderHexKey, String colorPath, String opacityPath) Legacy int-ARGB color (or an even older RGB-hex fallback key) → a ColorSetting {hex} map plus a separate 0–255 opacity value. -
migrateOpacityIntoColorAlpha
Standalone opacity setting → its color's own alpha channel, for elements that moved from "color + opacity" to a single alpha-enabled ColorSetting. An alpha-enabled color persists as{hex, alpha}, so the saved opacity just becomes the map'salphakey.defaultRgbcovers the case where opacity was customised but the color never was: without ahexbeside it the alpha would load against nothing and be dropped. -
migrateOverrideColorKey
Nullable-override color migration: the legacy key existing at all meant "the user set a custom color", so the toggleable ColorSetting loads enabled. -
getId
-
getX
public int getX() -
getY
public int getY() -
getWidth
public int getWidth() -
getHeight
public int getHeight() -
getReservedWidth
public int getReservedWidth()Minimum bounding-box size this element reserves on its parent runtime list/group, even whenareConditionsMet()returns false and the element is otherwise collapsed. Used so that the hotbar (which can disappear in spectator mode) still enforces a minimum width on the surrounding container, preventing siblings from re-flowing into the space the hotbar normally occupies. -
getReservedHeight
public int getReservedHeight() -
canResetToDefault
public boolean canResetToDefault()Whether this element supports the "Reset to default" context-menu action. Subclasses that have a meaningful default position (e.g. built-in HUD elements anchored to vanilla positions) should override and return true. -
resetToDefault
public void resetToDefault()Restore the constructor-supplied default anchor + offsets and persist them. -
getEditorAlpha
public float getEditorAlpha() -
setEditorAlpha
public void setEditorAlpha(float alpha) -
getExpandAnchorX
-
setExpandAnchorX
-
getExpandAnchorY
-
setExpandAnchorY
-
setClampSides
public void setClampSides(boolean left, boolean right, boolean top, boolean bottom) -
resetClampSides
public void resetClampSides() -
setExpandOverrides
-
clearExpandOverrides
public void clearExpandOverrides() -
setPosition
public void setPosition(int x, int y) -
contains
public boolean contains(double mx, double my) -
clamp
public void clamp(int screenWidth, int screenHeight) Clamp position to screen bounds, respecting screen margin and per-side flags. -
resolve
public void resolve(int screenW, int screenH) Resolve absolute x,y from the saved anchor + offset for the current screen size. Also clamps to keep the element on-screen. -
resolveEditor
public void resolveEditor(int screenW, int screenH) Editor-context resolve: same anchor math asresolve(int, int), but sized viaupdateEditorSize(net.minecraft.client.gui.Font)so elements whose live size depends on game state (target info collapses to 0×0 with no target, etc.) resolve at the size the editor displays and saves them with — otherwise their position would depend on whatever happened to be on screen at that moment. -
snapshotAnchor
public void snapshotAnchor(int screenW, int screenH) Snapshot the current absolute position into anchor + offset for the given screen size. Called after dragging finishes. Sizes viaupdateEditorSize(net.minecraft.client.gui.Font), never the live size: a state-dependent element saved while collapsed (0×0) bakes a zero-width offset and can flip the anchor column, so its position would shift on every relaunch where the game state differs from save time. -
resolvedExpandX
Resolve the effective expand anchor for an axis, handling AUTO by inferring from the element's screen position. -
resolvedExpandY
-
scalesWithTextScale
public boolean scalesWithTextScale()Whether this element scales with the global HUD text scale. Text-based elements returntrue; graphical elements (hotbar, item, icons, bars, models, maps) override this tofalseso the text scale only affects text and they keep their own per-element scale. -
getScale
public float getScale() -
setScale
public void setScale(float v) Set the per-element scale, snapping to the same GUI-scale-aware fraction stops as the Client tab. -
graphicalScale
public float graphicalScale()The element's per-element scale combined with the base HUD text scale — the total size multiplier an individually-scaleable graphical element should render at. -
effRenderScale
public float effRenderScale()The element's effective render scale (how much its logical size is multiplied to get the visual size). -
effWidth
public int effWidth()Visual (scaled) width — the logicalwidthmultiplied byeffRenderScale(). -
effHeight
public int effHeight()Visual (scaled) height — the logicalheightmultiplied byeffRenderScale(). -
wrapperScale
public float wrapperScale()Scale to pass to the sharedrender(net.minecraft.client.gui.GuiGraphics, net.minecraft.client.gui.Font)wrapper. Most graphical elements scale fully through the wrapper, so this returnsgraphicalScale()(per-element scale × base HUD scale). Elements that apply their per-element scale internally (item, armor, hotbar, boss bar, minimap) override this — toHudServices.getTextScale()when the wrapper should still apply the base scale on top of their internal per-element scale, or1.0when they apply the full scale themselves. -
usesBaseScaleSlider
public boolean usesBaseScaleSlider()Whether the editor should auto-add a generic "Scale" slider bound togetScale()/setScale(float). Elements that expose their own scale slider (item, armor) override this tofalse. -
render
public void render(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.client.gui.Font font) -
render
public void render(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.client.gui.Font font, float textScale) -
renderEditor
public void renderEditor(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.client.gui.Font font) -
renderEditor
public void renderEditor(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.client.gui.Font font, float textScale) -
renderContent
protected abstract void renderContent(net.minecraft.client.gui.GuiGraphics graphics, net.minecraft.client.gui.Font font) -
updateSize
protected abstract void updateSize(net.minecraft.client.gui.Font font) -
updateEditorSize
public void updateEditorSize(net.minecraft.client.gui.Font font) Update width/height as the editor would see them (with placeholder content). Subclasses that report 0 size outside the editor should override this. -
savePosition
public void savePosition(int screenW, int screenH) -
clearSavedPosition
public void clearSavedPosition()Remove saved position keys (for elements whose position is determined by a list). -
getConditions
-
addCondition
-
removeCondition
public void removeCondition(int index) -
areConditionsMet
public boolean areConditionsMet() -
getVisibilityKey
public int getVisibilityKey() -
getVisibilityKeyMode
-
isVisibilityHoldShows
public boolean isVisibilityHoldShows() -
setVisibilityKey
public void setVisibilityKey(int key) -
setVisibilityKeyMode
-
setVisibilityHoldShows
public void setVisibilityHoldShows(boolean holdShows) -
saveVisibilityKey
public void saveVisibilityKey() -
isEditorHidden
public boolean isEditorHidden() -
isDraggable
public boolean isDraggable()Whether the editor may move this element. Override tofalsefor an element that pins its own position (one drawn around the crosshair, say) — it stays selectable so its settings and properties window are still reachable, but a drag will not move it. Dragging one of those was only ever a no-op the next frame anyway, sinceresolvere-pins the position. -
saveConditions
public void saveConditions()
-