Hud
com.jsmacrosce.jsmacros.client.api.library.impl.FHud
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
renders
Methods
clearDraw2Ds
clearDraw3Ds
Unregisters all 3D overlays, including those registered by other scripts. This also removes prediction markers; FPlayer.setDrawPredictions(boolean) can register them again.
createDraw2D
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
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
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 screenmenuBackground: 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 screenmenuBackground: whether to draw the game's menu background overlayblurredBackground: whether to blur the world behind the screen
Returns: the new screen, not opened automatically
createTexture
Creates a mutable blank image and registers it under
name when non-null.Parameters:
width: the width of the canvasheight: the height of the canvasname: the name to register the texture under, ornullfor none
Returns: the new mutable image
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 foldername: the name to register the texture under, ornullfor none
Returns: the loaded image, or
null if reading fails or the format is unsupportedgetMouseX
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
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
getOpenScreenName
getRegisteredTextures
Returns a snapshot of the registered custom textures, keyed by registration name.
Returns: an immutable snapshot of the registered textures
getScaleFactor
Returns the configured GUI scale option; automatic scaling is reported as
0.Returns: the configured GUI scale option
getWindowHeight
Returns the game window height in raw (unscaled) pixels.
Returns: the current window height.
getWindowWidth
Returns the game window width in raw (unscaled) pixels.
Returns: the current window width.
isContainer
Returns whether the current screen is a container screen.
Returns:
true if the current screen is a container screen