Skip to content

Hud ​

com.jsmacrosce.jsmacros.client.api.library.impl.FHud

Since1.0.5

Screen, overlay, texture, and window-state APIs exposed to scripts as Hud.

2D overlay coordinates and mouse positions use GUI-scaled pixels from the window's top left;
window width and height are raw pixels. 3D overlays use world coordinates. Overlays render only while registered; use their own register() and unregister() methods. The clear methods remove all overlays of their respective dimension, including those registered by other scripts.

js
// draw 2D text in the overlay and register it
const draw = Hud.createDraw2D();  
draw.addText("hello", 10, 10, Color.rgb(0xFF, 0xFF, 0xFF), true);  
draw.register();

Accessible in scripts via the global Hud variable.

Fields ​

overlays ​

static overlays: Set<IDraw2D<Draw2D>>Since1.0.5read-only#
Set of 2D overlays currently registered for rendering.

renders ​

static renders: Set<Draw3D>Since1.0.6read-only#
Set of 3D overlays currently registered for rendering.

Methods ​

clearDraw2Ds ​

clearDraw2Ds(): voidSince1.0.5#
Unregisters all 2D overlays, including those registered by other scripts; the overlay objects and their elements remain available.

See:

clearDraw3Ds ​

clearDraw3Ds(): voidSince1.0.6#
Unregisters all 3D overlays, including those registered by other scripts. This also removes prediction markers; FPlayer.setDrawPredictions(boolean) can register them again.

createDraw2D ​

createDraw2D(): Draw2DSince1.0.5#
Creates an unregistered 2D overlay. It renders while registered; registering runs its init function. Coordinates use GUI-scaled pixels from the top left, as do getMouseX() and getMouseY().
Returns: a new, unregistered overlay

See:

createDraw3D ​

createDraw3D(): Draw3DSince1.0.6#
Creates an unregistered 3D overlay. Its elements use world-space block coordinates and render relative to the camera only while registered; unlike a 2D overlay, it has no init function.
// a wireframe box around a single block
const draw = Hud.createDraw3D();
draw.addBox(0, 64, 0, 1, 65, 1, Color.rgb(0xFF, 0x00, 0x00), Color.argb(0, 0, 0, 0), false);
draw.register();
Returns: a new unregistered Draw3D

createScreen ​

createScreen(String title, boolean menuBackground): ScriptScreenSince1.0.5#
Creates a script screen with the given title and both background effects enabled: the game's menu background overlay is drawn and the world behind it is blurred. The title is drawn by default; set drawTitle on the returned screen to disable it.

Parameters:

  • title: the title shown at the top of the screen
  • menuBackground: whether to draw the game's menu background overlay
Returns: the new screen, not opened automatically
createScreen(String title, boolean menuBackground, boolean blurredBackground): ScriptScreenSince2.0.0#
Creates a script screen with the given title and background effects. The title is drawn by default; set drawTitle on the returned screen to disable it. The two effects are independent. The menu background is vanilla's darkened background: on the supported versions it is a flat translucent black overlay rather than a picture, so it only darkens what is behind the screen. The blurred background applies vanilla's menu blur to the world behind the screen. With both off, the world is shown unmodified.

Parameters:

  • title: the title shown at the top of the screen
  • menuBackground: whether to draw the game's menu background overlay
  • blurredBackground: whether to blur the world behind the screen
Returns: the new screen, not opened automatically

createTexture ​

createTexture(int width, int height, String name): CustomImageSince1.8.4#
Creates a mutable blank image and registers it under name when non-null.

Parameters:

  • width: the width of the canvas
  • height: the height of the canvas
  • name: the name to register the texture under, or null for none
Returns: the new mutable image
createTexture(String path, String name): CustomImageSince1.8.4#
Loads an image from a path relative to the JsMacros config folder. Logs an error and returns null if reading fails or no image reader recognizes the file.

Parameters:

  • path: path to an image file, relative to the JsMacros config folder
  • name: the name to register the texture under, or null for none
Returns: the loaded image, or null if reading fails or the format is unsupported

getMouseX ​

getMouseX(): doubleSince1.1.3#
Returns the mouse's horizontal position in GUI-scaled pixels, matching 2D overlay coordinates. The scaled value is not necessarily an integer.
Returns: the current X coordinate of the mouse

getMouseY ​

getMouseY(): doubleSince1.1.3#
Returns the mouse's vertical position in GUI-scaled pixels, matching 2D overlay coordinates. The scaled value is not necessarily an integer.
Returns: the current Y coordinate of the mouse

getOpenScreen ​

getOpenScreen(): IScreenSince1.2.7#
Returns the currently open screen, if any.
Returns: the currently open screen, or null if none

getOpenScreenName ​

getOpenScreenName(): StringSince1.0.5#
Returns a name for the open screen: recognized screens use fixed names, other screens use their title (or unknown when it is empty). Returns null when no screen is open.
Returns: the screen name, or null if no screen is open

Note: renamed from getOpenScreen in 1.2.7

getRegisteredTextures ​

getRegisteredTextures(): Map<String, CustomImage>Since1.8.4#
Returns a snapshot of the registered custom textures, keyed by registration name.
Returns: an immutable snapshot of the registered textures

getScaleFactor ​

getScaleFactor(): intSince1.8.4#
Returns the configured GUI scale option; automatic scaling is reported as 0.
Returns: the configured GUI scale option

getWindowHeight ​

getWindowHeight(): intSince1.8.4#
Returns the game window height in raw (unscaled) pixels.
Returns: the current window height.

getWindowWidth ​

getWindowWidth(): intSince1.8.4#
Returns the game window width in raw (unscaled) pixels.
Returns: the current window width.

isContainer ​

isContainer(): booleanSince1.1.2#
Returns whether the current screen is a container screen.
Returns: true if the current screen is a container screen

listDraw2Ds ​

listDraw2Ds(): List<IDraw2D<Draw2D>>Since1.0.5#
Returns a snapshot of all currently registered 2D overlays, including those registered by other scripts.
Returns: the currently registered overlays

See:

listDraw3Ds ​

listDraw3Ds(): List<Draw3D>Since1.0.6#
Returns a snapshot of the 3D overlays currently registered for rendering, including those registered by other scripts.
Returns: the currently registered Draw3D overlays

openScreen ​

openScreen(IScreen s): voidSince1.0.5#
Opens a screen, or closes the current screen when passed null. The change is queued on the client thread, so it may not have taken effect when this method returns.

Parameters:

  • s: the screen to open, or null to close the current one