Skip to content

Line ​

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

Since1.8.4

A line is defined by two endpoints, a stroke thickness, and a rotation. The endpoint differences determine its scaled width and height; width is the stroke thickness. Nonpositive or non-finite thickness is not rendered. Positive fractional thickness and length are drawn as stored rather than rounded,
although the renderer raises thickness to at least one physical pixel and does not antialias the strip's edges. Rotation is about the first endpoint by default, or the midpoint when rotateCenter is true. Constructors and setRotation(double) normalize finite angles to [-180, 180).

js
const draw = Hud.createDraw2D();  
const line = draw.addLine(0, 0, 50, 50, Color.rgb(0xFF, 0xFF, 0xFF), 0, 2);  
draw.register();  
Chat.log(`${line.getWidth()} thick, reaching ${line.getScaledWidth()} across`);

Available in scripts as RenderElements.Line.

Nested types ​

Constructors ​

new Line ​

new Line(int x1, int y1, int x2, int y2, int color, float rotation, float width, int zIndex)#
Creates a line between two endpoints. Finite rotations are normalized to [-180, 180). The color is processed by setColor(int); a zero-alpha color becomes opaque except for pure black.

Parameters:

  • x1: the x position of the start of the line
  • y1: the y position of the start of the line
  • x2: the x position of the end of the line
  • y2: the y position of the end of the line
  • color: the color, with the alpha in the top byte
  • rotation: the rotation in degrees
  • width: the thickness of the line
  • zIndex: the z-index against the other elements on the overlay

Fields ​

color ​

color: int#
The packed ARGB color. Colors with a zero alpha byte are made opaque except for pure black.

parent ​

parent: IDraw2D<?>#
The overlay this line belongs to, or null if it is not attached to one. Parent dimensions then fall back to the GUI-scaled window dimensions.

rotateCenter ​

rotateCenter: boolean#
Whether rotation is about the midpoint rather than the first endpoint. Directly constructed lines default to false; builder-created lines default to true.

rotation ​

rotation: float#
The rotation in degrees. Constructors and setRotation(double) normalize finite angles to [-180, 180); direct field writes do not.

width ​

width: float#
The stroke thickness in screen pixels. The value is stored as a float; the builder defaults to one, and the 2D renderer draws fractional widths as stored, clamped to at least one physical pixel.

x1 ​

x1: int#
The x coordinate of the first endpoint. Endpoint order is caller-defined.

x2 ​

x2: int#
The x coordinate of the second endpoint.

y1 ​

y1: int#
The y coordinate of the first endpoint.

y2 ​

y2: int#
The y coordinate of the second endpoint.

zIndex ​

zIndex: int#
Draw-order value relative to other elements on the overlay; lower values are drawn first.

Methods ​

getAlpha ​

getAlpha(): intSince1.8.4#
Returns the top byte of the packed color, from 0 (transparent) to 255 (opaque).
Returns: the alpha value of the line's color.

getColor ​

getColor(): intSince1.8.4#
Returns the packed ARGB color currently stored on the line.
Returns: the color of the line.

getParentHeight ​

getParentHeight(): int#
Returns the parent overlay's height, or the GUI-scaled window height if no parent is set.
Returns: the height of the parent

getParentWidth ​

getParentWidth(): int#
Returns the parent overlay's width, or the GUI-scaled window width when no parent is set.
Returns: the width of the parent

getRotation ​

getRotation(): floatSince1.8.4#
Returns the stored rotation in degrees. Constructors and setters normalize finite angles; direct writes to the public field do not.
Returns: the rotation (clockwise) of the line.

getScaledHeight ​

getScaledHeight(): int#
Returns the absolute difference between the line's two y coordinates.
Returns: the scaled height

getScaledLeft ​

getScaledLeft(): int#
Returns the smaller of the line's two x coordinates.
Returns: the position of the scaled element's left side

getScaledTop ​

getScaledTop(): int#
Returns the smaller of the line's two y coordinates.
Returns: the position of the scaled element's top side

getScaledWidth ​

getScaledWidth(): int#
Returns the absolute difference between the line's x coordinates.
Returns: the scaled width

getWidth ​

getWidth(): floatSince1.8.4#
Returns the line's stroke thickness in screen pixels.
Returns: the width of the line.

getX1 ​

getX1(): intSince1.8.4#
Returns the x coordinate of the first endpoint, which need not be the leftmost.
Returns: the x position of the start of the line.

getX2 ​

getX2(): intSince1.8.4#
Returns the x coordinate of the second endpoint, which need not be the rightmost.
Returns: the x position of the end of the line.

getY1 ​

getY1(): intSince1.8.4#
Returns the y coordinate of the first endpoint, which need not be the topmost.
Returns: the y position of the start of the line.

getY2 ​

getY2(): intSince1.8.4#
Returns the y coordinate of the line's second endpoint.
Returns: the y position of the end of the line.

getZIndex ​

getZIndex(): int#
Returns this line's draw-order value.
Returns: the z-index of this element

isRotatingCenter ​

isRotatingCenter(): booleanSince1.8.4#
Returns whether rotation is about this line's midpoint.
Returns: true if this line should be rotated around its center, false otherwise.

moveTo ​

moveTo(int x, int y): Line#
Moves the line so its minimum x and y coordinates match the requested position, translating both endpoints without changing their relative positions.

Parameters:

  • x: the new x position
  • y: the new y position
Returns: self for chaining.

render ​

render(GuiGraphics drawContext, int mouseX, int mouseY, float delta): void#
Draws the line as a filled strip between its endpoints, applying the element's rotation and endpoint orientation. Nonpositive and non-finite widths skip drawing. The strip is a unit rectangle scaled by the line's length and thickness, so fractional widths keep their stored size instead of being rounded. Thickness is raised to at least one physical pixel so very thin lines still appear, and the GUI renderer does not antialias the strip's edges. The mouse coordinates and frame delta are unused. The graphics pose is pushed and popped on normal completion.

Parameters:

  • drawContext: the graphics context receiving the strip
  • mouseX: unused mouse x coordinate
  • mouseY: unused mouse y coordinate
  • delta: unused frame delta

setAlpha ​

setAlpha(int alpha): LineSince1.8.4#
Sets the alpha byte without changing the RGB channels. Values are not clamped.

Parameters:

  • alpha: the alpha value of the line's color
Returns: self for chaining.

setColor ​

setColor(int color): LineSince1.8.4#
Sets the packed ARGB color. A zero alpha byte with nonzero RGB is treated as opaque; pure black remains transparent.

Parameters:

  • color: the color of the line
Returns: self for chaining.
setColor(int color, int alpha): LineSince1.8.4#
Sets the RGB color and alpha separately. The alpha replaces the top byte and is not clamped; only its low eight bits are returned by getAlpha().

Parameters:

  • color: the color of the line
  • alpha: the alpha of the line
Returns: self for chaining.

setParent ​

setParent(IDraw2D<?> parent): Line#
Sets the overlay used for parent-relative dimensions and alignment. Passing null makes parent dimensions fall back to the window.

Parameters:

  • parent: the overlay this element is on, or null for the window
Returns: self for chaining.

setPos ​

setPos(int x1, int y1, int x2, int y2): LineSince1.8.4#
Sets both endpoints of the line.

Parameters:

  • x1: the x position of the start of the line
  • y1: the y position of the start of the line
  • x2: the x position of the end of the line
  • y2: the y position of the end of the line
Returns: self for chaining.

setPos1 ​

setPos1(int x1, int y1): LineSince1.8.4#
Sets both coordinates of the first endpoint without changing the second.

Parameters:

  • x1: the x position of the start of the line
  • y1: the y position of the start of the line
Returns: self for chaining.

setPos2 ​

setPos2(int x2, int y2): LineSince1.8.4#
Sets the second endpoint, leaving the first unchanged.

Parameters:

  • x2: the x position of the end of the line
  • y2: the y position of the end of the line
Returns: self for chaining.

setRotateCenter ​

setRotateCenter(boolean rotateCenter): LineSince1.8.4#
Selects whether rotation is about the line's midpoint or its first endpoint.

Parameters:

  • rotateCenter: whether this line should be rotated around its center
Returns: self for chaining.

setRotation ​

setRotation(double rotation): LineSince1.8.4#
Sets the rotation in degrees, normalized by Minecraft's degree-wrapping function. Rotation is about the midpoint when rotateCenter is true, otherwise about the first endpoint.

Parameters:

  • rotation: the rotation (clockwise) of the line
Returns: self for chaining.

setWidth ​

setWidth(double width): LineSince1.8.4#
Sets the line's stroke thickness in screen pixels. Values are stored as floats; non-positive and non-finite widths are not rendered, and positive fractional widths keep their size when drawn, clamped to at least one physical pixel.

Parameters:

  • width: the width of the line
Returns: self for chaining.

setX1 ​

setX1(int x1): LineSince1.8.4#
Sets the first endpoint's x coordinate without changing the other coordinates.

Parameters:

  • x1: the x position of the start of the line
Returns: self for chaining.

setX2 ​

setX2(int x2): LineSince1.8.4#
Sets the second endpoint's x coordinate without changing the other coordinates.

Parameters:

  • x2: the x position of the end of the line
Returns: self for chaining.

setY1 ​

setY1(int y1): LineSince1.8.4#
Sets the first endpoint's y coordinate without changing the other coordinates.

Parameters:

  • y1: the y position of the start of the line
Returns: self for chaining.

setY2 ​

setY2(int y2): LineSince1.8.4#
Sets the second endpoint's y coordinate without changing the other coordinates.

Parameters:

  • y2: the y position of the end of the line
Returns: self for chaining.

setZIndex ​

setZIndex(int zIndex): LineSince1.8.4#
Sets this line's draw-order value relative to other elements in its overlay; lower values are drawn first. Equal values retain insertion order in the overlay.

Parameters:

  • zIndex: the z-index of the line
Returns: self for chaining.