Skip to content

RenderElement ​

com.jsmacrosce.jsmacros.client.api.classes.render.components.RenderElement

A renderable element that can be added to a 2D overlay. The overlay orders its elements by z-index and renders them each frame. Lower z-indexes draw first; ties retain insertion order.

Use the RenderElements types, such as RenderElements.Text, to identify a specific element from an overlay's element list.

js
const draw = Hud.createDraw2D();  
const back = draw.addRect(0, 0, 100, 100, Color.rgb(0x00, 0x00, 0x00));  
const front = draw.addRect(10, 10, 50, 50, Color.rgb(0xFF, 0x00, 0x00));  
// sorted by z-index lowest first, and a tie keeps the order the two were added in
front.setZIndex(back.getZIndex() + 1);  

// namespace types narrow the mixed list the overlay hands back
for (const element of draw.getElements()) {
  if (element instanceof RenderElements.Rect) {
    Chat.log(`rect at ${element.getX1()}, ${element.getY1()}, z ${element.getZIndex()}`);  
  }
}
draw.register();

Available in scripts as RenderElements.Element.

Fields ​

mc ​

static mc: Minecraftread-only#
The Minecraft client instance used by render elements to access client resources such as the font and window.

Methods ​

getZIndex ​

getZIndex(): int#
Returns this element's ordering value on its overlay. Lower values draw first; equal values retain insertion order. This is distinct from the value used to order whole overlays by IDraw2D.getZIndex() instead, which is a different number on a different object.
Returns: the z-index of this element

render ​

render(GuiGraphicsExtractor drawContext, int mouseX, int mouseY, float delta): void#
Collects this element's GUI render state when called by its overlay or screen. A plain overlay passes zero for the mouse coordinates and frame value; a screen forwards its current values.

Parameters:

  • drawContext: the graphics context used to collect render state
  • mouseX: the mouse x-coordinate, or 0 on a plain overlay
  • mouseY: the mouse y-coordinate, or 0 on a plain overlay
  • delta: the frame value supplied by the caller, or 0 on a plain overlay