Class EnchantWidget
java.lang.Object
johnsmith.enchantingoverhauled.client.gui.widget.enchant.EnchantWidget
- Direct Known Subclasses:
EnchantWidget.Available,EnchantWidget.Empty,EnchantWidget.Locked,EnchantWidget.Maxed,EnchantWidget.Overleveled
public abstract sealed class EnchantWidget
extends Object
permits EnchantWidget.Empty, EnchantWidget.Available, 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 ClassesModifier and TypeClassDescriptionstatic final classRepresents a standard, interactable enchantment option within the Enchantment Screen.static final classA 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 classRepresents 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 classRepresents a non-interactable enchantment slot where the target item's enchantment has reached its natural maximum level.static final classRepresents 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
FieldsModifier and TypeFieldDescriptionprotected 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.IdentifierThe font identifier for the standard galactic alphabet used for obfuscation.booleanTracks if the mouse pointer is currently positioned over this widget bounds.protected final WidgetLayoutConfigThe configuration mapping the dimensions and internal offsets for rendering text and sprites.protected Runnableprotected EnchantRenderStateprotected intprotected final booleanprotected intprotected int -
Constructor Summary
ConstructorsConstructorDescriptionEnchantWidget(int x, int y, EnchantRenderState state, int texIndex, boolean usePlainBackground, Runnable onPressAction) Constructs a base EnchantWidget. -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddrawScrollingString(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.MutableComponentFormats the underlying enchantment name, resolving theme coloring and obfuscation dynamically.getState()Retrieves the current rendering state encapsulated by this widget.booleanmouseClicked(double mouseX, double mouseY, int button) Evaluates click events.voidrender(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 voidrenderWidget(net.minecraft.client.gui.GuiGraphics context, int mouseX, int mouseY, float partialTick) The internal rendering logic defined by the specific widget subclass.voidsetOnPressAction(Runnable onPressAction) Overwrites the callback execution block bound to a successful click event.voidsetState(EnchantRenderState state) Updates the underlying data state of this widget.voidsetTexIndex(int texIndex) Updates the visual texture variant index used by the widget.voidupdatePosition(int x, int y) Updates the screen coordinates of this widget without re-instantiation.
-
Field Details
-
GALACTIC_FONT_ID
protected static final net.minecraft.resources.Identifier GALACTIC_FONT_IDThe font identifier for the standard galactic alphabet used for obfuscation. -
ENABLED_LEVEL_SPRITES
protected static final net.minecraft.resources.Identifier[] ENABLED_LEVEL_SPRITESCost indicator sprites for active, affordable enchantments. -
DISABLED_LEVEL_SPRITES
protected static final net.minecraft.resources.Identifier[] DISABLED_LEVEL_SPRITESCost indicator sprites for disabled, unaffordable, or locked enchantments. -
layout
The configuration mapping the dimensions and internal offsets for rendering text and sprites. -
x
protected int x -
y
protected int y -
state
-
texIndex
protected int texIndex -
usePlainBackground
protected final boolean usePlainBackground -
onPressAction
-
isHovered
public boolean isHoveredTracks if the mouse pointer is currently positioned over this widget bounds.
-
-
Constructor Details
-
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
Retrieves the current rendering state encapsulated by this widget.- Returns:
- The active
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
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.
-