BaseScreen
com.jsmacrosce.wagyourgui.BaseScreen
Base class for screens that host nested overlays and retain a navigation parent.
Subclasses provide GUI initialization and rendering behavior. The client stores the most recently initialized instance in prevScreen; that need not be the currently displayed screen.
js
const Client = Java.type('com.jsmacrosce.jsmacros.client.JsMacrosClient');
const screen = Client.prevScreen;
if (screen !== null) {
screen.reload();
}Methods
addRenderableWidget
addRenderableWidget(T extends GuiEventListener & Renderable & NarratableEntry renderableWidget): T extends GuiEventListener & Renderable & NarratableEntry#Registers a widget for input, rendering, and narration, returning the same widget. This adds to the native rendering, input and narration lists without duplicate filtering or overlay-local tracking.
Parameters:
renderableWidget: non-null widget to register
Type Parameters:
T: widget type supporting input, rendering, and narration
Returns: the supplied widget reference
closeOverlay
closeOverlay(OverlayContainer overlay): void#Removes the supplied overlay's tracked widgets from this screen, restores its saved widget states, and calls its close hook. The supplied overlay need not be this screen's current overlay; only a matching current reference is cleared, after the hook returns. A hook failure leaves that reference uncleared. The supplied tracking list, saved-state map and child overlay are not cleared or recursively closed.
Parameters:
overlay: overlay to clean up and notify, ornullfor a no-op
getChildOverlay
getChildOverlay(): OverlayContainer#Returns the deepest open overlay, or
null when none is open.Returns: deepest open overlay, or
nullgetFirstOverlayParent
getFirstOverlayParent(): IOverlayParent#Returns this screen as the first overlay host.
Returns: this screen as overlay host
keyPressed
On Escape with a direct overlay, requests closing its deepest overlay and returns true if closing returns normally. Other paths delegate to the native screen handler; this method does not forward ordinary keys directly to the overlay's key hook.
Parameters:
keyEvent: non-null native key event; its key code is tested for Escape before inspecting the overlay, and the event is forwarded unchanged on delegation
Returns: true for the intercepted Escape path, otherwise the native screen handler's result
mouseClicked
mouseClicked(MouseButtonEvent buttonEvent, boolean doubleClick): boolean#Calls the direct overlay's click hook, if present, before delegating to the native screen handler. Overlay presence does not itself consume the click; if the overlay hook throws, native delegation is not reached.
Parameters:
buttonEvent: non-null native click event forwarded unchanged to the overlay and native handlerdoubleClick: caller-supplied double-click flag forwarded unchanged; this method does not compute it
Returns: the native screen handler's result, not the overlay hook's handling state
mouseScrolled
mouseScrolled(double mouseX, double mouseY, double horiz, double vert): boolean#If the direct overlay has a scrollbar, forwards vertical scrolling to it as a drag, then delegates the original scroll event to the native screen handler. The drag uses zero horizontal delta and -2 times the vertical scroll amount, without a local activation or visibility check. Its result is ignored; a failure prevents native delegation.
Parameters:
mouseX: mouse X coordinate in GUI spacemouseY: mouse Y coordinate in GUI spacehoriz: horizontal scroll amount, forwarded unchanged to the native handlervert: vertical scroll amount, multiplied by -2 for the scrollbar drag
Returns: the native screen handler's result, not whether the scrollbar moved
onClose
onClose(): void#With no loaded level, calls the overridable openParent; with a level, explicitly clears focus and asks the client to clear the current screen. Expects the Minecraft client to be assigned. Does not call updateSettings or explicitly close overlays or clear their saved state.
openOverlay
openOverlay(OverlayContainer overlay): void#Opens an overlay at the deepest open level, saving and deactivating existing host-level AbstractWidget entries by default.
Parameters:
overlay: non-null overlay to open
openOverlay(OverlayContainer overlay, boolean disableButtons): void#Opens an overlay at the deepest level; at this level, optionally saves and deactivates existing widgets. Only existing AbstractWidget entries are deactivated; false leaves their active states unchanged. The overlay is assigned before its initialization, so an initialization failure leaves the assignment and any deactivation in place. Saved-state entries are merged rather than cleared, and the overlay is not automatically reparented.
Parameters:
overlay: non-null overlay to opendisableButtons: whether to save and deactivate existing host-level widgets
openParent
openParent(): void#Asks the client to open the stored parent screen, or clear the current screen when the parent is null. Expects the Minecraft client to be assigned. Does not call updateSettings, clear the stored parent, or explicitly close overlays.
reload
reload(): void#Invokes this screen's overridable initialization without opening it; the base implementation expects the Minecraft client to be assigned. The base initialization clears registered widgets and discards the current overlay without its normal close callback or saved active-state restoration, then records this instance as
prevScreen.removed
removed(): void#Base implementation performs only an assertion that the client is available.
removeWidget
removeWidget(GuiEventListener btn): void#Removes a listener from this screen's native widget registrations. Removes one matching entry from each applicable rendering, narration and input list, not from an overlay's local tracking list. On Minecraft 1.21.10 and later, native removal clears focus when this is the focused listener; 1.21.5 and 1.21.8 do not.
Parameters:
btn: listener to remove
render
render(GuiGraphics drawContext, int mouseX, int mouseY, float delta): void#Renders the direct overlay when present without calling the superclass to render this screen's own widgets. Minecraft 1.21.5 first renders the screen background, even without an overlay; later targets using this hook do not automatically render that background. Subclasses handle their own widgets.
Parameters:
drawContext: non-null native graphics contextmouseX: mouse X coordinate in GUI spacemouseY: mouse Y coordinate in GUI spacedelta: frame value forwarded to the overlay
setFocused
setFocused(GuiEventListener focused): void#Sets the current focused listener, unfocusing the old listener and focusing a non-null replacement even if it is not registered as a child. A null replacement clears focus; this does not register a widget or check its visibility or activation.
Parameters:
focused: listener to focus, or null to clear focus
setParent
shouldCloseOnEsc
shouldCloseOnEsc(): boolean#Reports whether the native Escape-close path is allowed; this query does not close anything.
Returns: true when no direct overlay is set, false otherwise
trimmed
static trimmed(Font textRenderer, FormattedText str, int width): FormattedCharSequence#Trims formatted text to a font-measured prefix and applies the current language's visual ordering.
Parameters:
textRenderer: non-null font used to measure the trimmed prefixstr: non-null formatted text in logical orderwidth: requested maximum measured width
Returns: language-ordered sequence for the trimmed prefix
updateSettings
updateSettings(): void#No-op extension hook for subclass settings updates or persistence. BaseScreen does not automatically invoke it from closing, parent navigation, reinitialization or removal.