Class HUDElement

java.lang.Object
me.hackware.api.hud.HUDElement
All Implemented Interfaces:
SettingContainer
Direct Known Subclasses:
TextHUDElement, VanillaHUDElement

public abstract class HUDElement extends Object implements SettingContainer
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.
  • Field Details

    • id

      protected final String id
    • x

      protected int x
      Current screen-space position (computed from anchor + offset each frame).
    • y

      protected int y
      Current 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

      protected HUDElement(String id, int defaultX, int defaultY)
    • HUDElement

      protected HUDElement(String id, int defaultX, int defaultY, HUDElement.Anchor defaultAnchor)
  • 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 returns 1.0. The user-facing HUD size multiplier is applied separately via HudServices.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

      protected <S extends Setting<?>> S addSettings(S setting)
      Registers a setting with this element and returns it (modules pattern).
    • addSettings

      protected void addSettings(Setting<?>... arr)
      Registers multiple settings at once.
    • getSettings

      public List<Setting<?>> 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:
      saveContainerSettings in interface SettingContainer
    • migrateSettingKey

      protected void migrateSettingKey(String legacyKey, String newPath)
      One-time key rename for the settings-definers migration: moves a legacy hud.<id>.<legacyKey> value onto the new slug path, verbatim.
    • migrateEnumSettingKey

      protected void migrateEnumSettingKey(String legacyKey, String newPath)
      Key rename with enum-value normalization (any legacy spelling → UPPER_SNAKE).
    • migrateSettingKey

      protected void migrateSettingKey(String legacyKey, String newPath, UnaryOperator<Object> convert)
    • migrateColorSettingKey

      protected void migrateColorSettingKey(String legacyColorKey, String legacyEnabledKey, String newPath)
      Key rename onto a ColorSetting path: 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

      protected void migrateOpacityIntoColorAlpha(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. An alpha-enabled color persists as {hex, alpha}, so the saved opacity just becomes the map's alpha key.

      defaultRgb covers the case where opacity was customised but the color never was: without a hex beside it the alpha would load against nothing and be dropped.

    • migrateOverrideColorKey

      protected void migrateOverrideColorKey(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.
    • getId

      public String 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 when areConditionsMet() 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

      public HUDElement.ExpandAnchorX getExpandAnchorX()
    • setExpandAnchorX

      public void setExpandAnchorX(HUDElement.ExpandAnchorX v)
    • getExpandAnchorY

      public HUDElement.ExpandAnchorY getExpandAnchorY()
    • setExpandAnchorY

      public void setExpandAnchorY(HUDElement.ExpandAnchorY v)
    • setClampSides

      public void setClampSides(boolean left, boolean right, boolean top, boolean bottom)
    • resetClampSides

      public void resetClampSides()
    • setExpandOverrides

      public void setExpandOverrides(HUDElement.ExpandAnchorX ox, HUDElement.ExpandAnchorY oy)
    • 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 as resolve(int, int), but sized via updateEditorSize(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 via updateEditorSize(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

      public HUDElement.ExpandAnchorX resolvedExpandX(int screenW)
      Resolve the effective expand anchor for an axis, handling AUTO by inferring from the element's screen position.
    • resolvedExpandY

      public HUDElement.ExpandAnchorY resolvedExpandY(int screenH)
    • scalesWithTextScale

      public boolean scalesWithTextScale()
      Whether this element scales with the global HUD text scale. Text-based elements return true; graphical elements (hotbar, item, icons, bars, models, maps) override this to false so 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 logical width multiplied by effRenderScale().
    • effHeight

      public int effHeight()
      Visual (scaled) height — the logical height multiplied by effRenderScale().
    • wrapperScale

      public float wrapperScale()
      Scale to pass to the shared render(net.minecraft.client.gui.GuiGraphics, net.minecraft.client.gui.Font) wrapper. Most graphical elements scale fully through the wrapper, so this returns graphicalScale() (per-element scale × base HUD scale). Elements that apply their per-element scale internally (item, armor, hotbar, boss bar, minimap) override this — to HudServices.getTextScale() when the wrapper should still apply the base scale on top of their internal per-element scale, or 1.0 when they apply the full scale themselves.
    • usesBaseScaleSlider

      public boolean usesBaseScaleSlider()
      Whether the editor should auto-add a generic "Scale" slider bound to getScale()/setScale(float). Elements that expose their own scale slider (item, armor) override this to false.
    • 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

      public List<HUDElement.VisibilityCondition> getConditions()
    • addCondition

      public void addCondition(HUDElement.VisibilityCondition condition)
    • removeCondition

      public void removeCondition(int index)
    • areConditionsMet

      public boolean areConditionsMet()
    • getVisibilityKey

      public int getVisibilityKey()
    • getVisibilityKeyMode

      public HUDElement.VisibilityKeyMode getVisibilityKeyMode()
    • isVisibilityHoldShows

      public boolean isVisibilityHoldShows()
    • setVisibilityKey

      public void setVisibilityKey(int key)
    • setVisibilityKeyMode

      public void setVisibilityKeyMode(HUDElement.VisibilityKeyMode mode)
    • 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 to false for 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, since resolve re-pins the position.
    • saveConditions

      public void saveConditions()