java.lang.Object
johnsmith.enchantingoverhauled.client.gui.widget.enchant.EnchantWidget
Direct Known Subclasses:
EnchantWidget.Available, EnchantWidget.Empty, EnchantWidget.Locked, EnchantWidget.Maxed, EnchantWidget.Overleveled

The abstract base class representing a single row item (widget) in the Enchanting Altar's UI list.

Widgets in this system are stateful; their internal coordinates, data state, and execution callbacks can be dynamically updated during pagination without needing to instantiate new objects, reducing memory churn.

This class is sealed, strictly defining its functional states via static nested classes.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Represents a standard, interactable enchantment option within the Enchantment Screen.
    static final class 
    A non-interactable filler widget used to pad the Enchantment Screen's list view when there are fewer active enchantment contexts available than the current page size.
    static final class 
    Represents a widget where the underlying enchantment action cannot be performed due to missing context criteria (e.g., attempting to upgrade an item but providing a source catalyst with an insufficient level or wrong type).
    static final class 
    Represents a non-interactable enchantment slot where the target item's enchantment has reached its natural maximum level.
    static final class 
    Represents a non-interactable enchantment slot where the target item's enchantment exceeds its natural maximum level (e.g., pushed beyond the limit via an Enchanted Tome).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final net.minecraft.resources.Identifier[]
    Cost indicator sprites for disabled, unaffordable, or locked enchantments.
    protected static final net.minecraft.resources.Identifier[]
    Cost indicator sprites for active, affordable enchantments.
    protected static final net.minecraft.resources.Identifier
    The font identifier for the standard galactic alphabet used for obfuscation.
    boolean
    Tracks if the mouse pointer is currently positioned over this widget bounds.
    protected final WidgetLayoutConfig
    The configuration mapping the dimensions and internal offsets for rendering text and sprites.
    protected Runnable
     
     
    protected int
     
    protected final boolean
     
    protected int
     
    protected int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    EnchantWidget(int x, int y, EnchantRenderState state, int texIndex, boolean usePlainBackground, Runnable onPressAction)
    Constructs a base EnchantWidget.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    drawScrollingString(net.minecraft.client.gui.GuiGraphics guiGraphics, net.minecraft.client.gui.Font font, net.minecraft.network.chat.Component text, int minX, int minY, int maxX, int color)
    Renders a marquee scrolling string if the text width exceeds the available max width bounding box.
    protected net.minecraft.network.chat.MutableComponent
    Formats the underlying enchantment name, resolving theme coloring and obfuscation dynamically.
    Retrieves the current rendering state encapsulated by this widget.
    boolean
    mouseClicked(double mouseX, double mouseY, int button)
    Evaluates click events.
    void
    render(net.minecraft.client.gui.GuiGraphics context, int mouseX, int mouseY, float partialTick)
    Evaluates the mouse hover state and delegates the actual drawing logic to the subclass.
    protected abstract void
    renderWidget(net.minecraft.client.gui.GuiGraphics context, int mouseX, int mouseY, float partialTick)
    The internal rendering logic defined by the specific widget subclass.
    void
    setOnPressAction(Runnable onPressAction)
    Overwrites the callback execution block bound to a successful click event.
    void
    Updates the underlying data state of this widget.
    void
    setTexIndex(int texIndex)
    Updates the visual texture variant index used by the widget.
    void
    updatePosition(int x, int y)
    Updates the screen coordinates of this widget without re-instantiation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • GALACTIC_FONT_ID

      protected static final net.minecraft.resources.Identifier GALACTIC_FONT_ID
      The font identifier for the standard galactic alphabet used for obfuscation.
    • ENABLED_LEVEL_SPRITES

      protected static final net.minecraft.resources.Identifier[] ENABLED_LEVEL_SPRITES
      Cost indicator sprites for active, affordable enchantments.
    • DISABLED_LEVEL_SPRITES

      protected static final net.minecraft.resources.Identifier[] DISABLED_LEVEL_SPRITES
      Cost indicator sprites for disabled, unaffordable, or locked enchantments.
    • layout

      protected final WidgetLayoutConfig layout
      The configuration mapping the dimensions and internal offsets for rendering text and sprites.
    • x

      protected int x
    • y

      protected int y
    • state

      protected EnchantRenderState state
    • texIndex

      protected int texIndex
    • usePlainBackground

      protected final boolean usePlainBackground
    • onPressAction

      protected Runnable onPressAction
    • isHovered

      public boolean isHovered
      Tracks if the mouse pointer is currently positioned over this widget bounds.
  • Constructor Details

    • EnchantWidget

      public EnchantWidget(int x, int y, EnchantRenderState state, int texIndex, boolean usePlainBackground, Runnable onPressAction)
      Constructs a base EnchantWidget.
      Parameters:
      x - The initial X screen coordinate.
      y - The initial Y screen coordinate.
      state - The rendering data state mapped to this slot.
      texIndex - The texture variant index (0-9).
      usePlainBackground - Whether to use the untextured button variants.
      onPressAction - The action callback triggered on successful click.
  • Method Details

    • getFormattedEnchantmentName

      protected net.minecraft.network.chat.MutableComponent getFormattedEnchantmentName(EnchantmentSource source)
      Formats the underlying enchantment name, resolving theme coloring and obfuscation dynamically.
    • drawScrollingString

      protected void drawScrollingString(net.minecraft.client.gui.GuiGraphics guiGraphics, net.minecraft.client.gui.Font font, net.minecraft.network.chat.Component text, int minX, int minY, int maxX, int color)
      Renders a marquee scrolling string if the text width exceeds the available max width bounding box.
    • getState

      public EnchantRenderState getState()
      Retrieves the current rendering state encapsulated by this widget.
      Returns:
      The active EnchantRenderState.
    • setState

      public void setState(EnchantRenderState state)
      Updates the underlying data state of this widget.
      Parameters:
      state - The new EnchantRenderState.
    • updatePosition

      public void updatePosition(int x, int y)
      Updates the screen coordinates of this widget without re-instantiation.
      Parameters:
      x - The new X coordinate.
      y - The new Y coordinate.
    • setTexIndex

      public void setTexIndex(int texIndex)
      Updates the visual texture variant index used by the widget.
      Parameters:
      texIndex - The new variant index (typically 0-9).
    • setOnPressAction

      public void setOnPressAction(Runnable onPressAction)
      Overwrites the callback execution block bound to a successful click event.
      Parameters:
      onPressAction - The new runnable task.
    • render

      public void render(net.minecraft.client.gui.GuiGraphics context, int mouseX, int mouseY, float partialTick)
      Evaluates the mouse hover state and delegates the actual drawing logic to the subclass.
      Parameters:
      context - The GUI graphics context to draw to.
      mouseX - The current mouse X coordinate.
      mouseY - The current mouse Y coordinate.
      partialTick - The partial tick time for animations.
    • renderWidget

      protected abstract void renderWidget(net.minecraft.client.gui.GuiGraphics context, int mouseX, int mouseY, float partialTick)
      The internal rendering logic defined by the specific widget subclass.
      Parameters:
      context - The GUI graphics context.
      mouseX - The mouse X coordinate.
      mouseY - The mouse Y coordinate.
      partialTick - The partial tick time.
    • mouseClicked

      public boolean mouseClicked(double mouseX, double mouseY, int button)
      Evaluates click events. Triggers the assigned action callback if the widget is hovered and the primary mouse button (Left-click) is used.
      Parameters:
      mouseX - The X coordinate of the mouse pointer.
      mouseY - The Y coordinate of the mouse pointer.
      button - The mouse button pressed (0 for Left-Click).
      Returns:
      true if the click was consumed, false otherwise.