Skip to content

Image ​

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

Since1.2.3

Draws a texture region at a position and destination size. width and height set the drawn size; imageX and imageY are pixel offsets normalized by textureWidth and textureHeight. Builders default texture dimensions to 256; constructors take them explicitly, so supply the actual dimensions when they differ.

regionWidth and regionHeight affect 3D rendering only; 2D rendering derives the sampled extent from destination and texture dimensions.

js
const draw = Hud.createDraw2D();  
const icon = draw.imageBuilder("minecraft:item/diamond").size(16, 16).buildAndAdd();  
draw.register();  
Chat.log(`texture is ${icon.textureWidth} by ${icon.textureHeight}`);

Available in scripts as RenderElements.Image.

Nested types ​

Constructors ​

new Image ​

new Image(int x, int y, int width, int height, int zIndex, int color, String id, int imageX, int imageY, int regionWidth, int regionHeight, int textureWidth, int textureHeight, float rotation)#
constructs an image from a texture region, applying the single-argument tint rules. A bare texture name gets the minecraft namespace. Finite rotations are normalized to [-180, 180). Tint handling follows setColor(int), including its special handling of transparent black.

Parameters:

  • x: the x position of the image
  • y: the y position of the image
  • width: the width the piece is drawn at
  • height: the height the piece is drawn at
  • zIndex: the z-index against the other elements on the overlay
  • color: the tint, with the alpha in the top byte
  • id: the texture to draw from, with the namespace optional
  • imageX: the x position in the texture to start from
  • imageY: the y position in the texture to start from
  • regionWidth: the width of the region to take
  • regionHeight: the height of the region to take
  • textureWidth: the width of the whole texture
  • textureHeight: the height of the whole texture
  • rotation: the rotation in degrees, normalized to [-180, 180)
new Image(int x, int y, int width, int height, int zIndex, int alpha, int color, String id, int imageX, int imageY, int regionWidth, int regionHeight, int textureWidth, int textureHeight, float rotation)#
constructs an image from a texture region, with alpha supplied separately. The alpha replaces the top byte of the colour outright, so a colour that came with an alpha of its own loses it, and a value outside 0 to 255 is not clamped. As in the shorter constructor finite rotations are normalized to [-180, 180).

Parameters:

  • x: the x position of the image
  • y: the y position of the image
  • width: the width the piece is drawn at
  • height: the height the piece is drawn at
  • zIndex: the z-index against the other elements on the overlay
  • alpha: the alpha, in the top byte
  • color: the colour, whose top byte is replaced
  • id: the texture to draw from, with the namespace optional
  • imageX: the x position in the texture to start from
  • imageY: the y position in the texture to start from
  • regionWidth: the width of the region to take
  • regionHeight: the height of the region to take
  • textureWidth: the width of the whole texture
  • textureHeight: the height of the whole texture
  • rotation: the rotation in degrees, normalized to [-180, 180)

Fields ​

color ​

color: int#
the tint, packed with the alpha in the top byte. A colour with no alpha of its own is made opaque unless it was pure black; for example, a bare RGB red is stored with alpha 0xFF.

height ​

height: int#
The destination height, independent of the source region height.

imageX ​

imageX: int#
The horizontal source offset in pixels, normalized by textureWidth for rendering.

imageY ​

imageY: int#
the vertical source offset in the texture, in pixels.

parent ​

parent: IDraw2D<?>#
The overlay this image belongs to, or null when it is not bound to an overlay.

regionHeight ​

regionHeight: int#
the source-region height; used by the 3D path, but not by the 2D overlay.

regionWidth ​

regionWidth: int#
the source-region width; used by the 3D path, but not by the 2D overlay.

rotateCenter ​

rotateCenter: boolean#
Whether rotation is about the center of the destination rectangle rather than its position.

rotation ​

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

textureHeight ​

textureHeight: int#
the texture height used to convert the pixel source offset to a texture coordinate. Builders default this to 256; set it to the actual texture height otherwise.

textureWidth ​

textureWidth: int#
the texture width used to convert the pixel source offset to a texture coordinate. Builders default this to 256; set it to the actual texture width otherwise.

width ​

width: int#
The destination width, independent of the source region width.

x ​

x: int#
The x coordinate where this image is drawn.

y ​

y: int#
The y coordinate where this image is drawn.

zIndex ​

zIndex: int#
the number this image is ordered against the other elements on its overlay, lower drawn first.

Methods ​

getAlpha ​

getAlpha(): intSince1.8.4#
Returns the alpha byte of the stored tint, from 0 (transparent) to 255 (opaque). Use setColor(int, int) to set alpha explicitly.
Returns: the unsigned alpha byte from 0 to 255

getColor ​

getColor(): intSince1.8.4#
Returns the packed tint currently stored by this image, with alpha in the top byte.
Returns: the packed ARGB tint

getHeight ​

getHeight(): intSince1.8.4#
Returns the destination height, independent of the texture region.
Returns: the height of this image.

getImage ​

getImage(): StringSince1.2.3#
Returns the resolved texture identifier in namespace:path form. Throws NullPointerException if no texture has been set.
Returns: the texture identifier

getParentHeight ​

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

getParentWidth ​

getParentWidth(): int#
Returns the parent overlay width, or the window's GUI-scaled 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 wrap the angle; direct writes to the public field do not.
Returns: the stored angle in degrees

getScaledHeight ​

getScaledHeight(): int#
Returns the destination height used for alignment; images have no additional scale.
Returns: the scaled height of this element

getScaledLeft ​

getScaledLeft(): int#
Returns the image's x position, which is its left edge.
Returns: the position of the scaled element's left side

getScaledTop ​

getScaledTop(): int#
Returns the image's y position, which is its top edge.
Returns: the position of the scaled element's top side

getScaledWidth ​

getScaledWidth(): int#
Returns the destination width used for alignment; images have no additional scale.
Returns: the scaled width of this element

getWidth ​

getWidth(): intSince1.8.4#
Returns the destination width, which is independent of the texture region.
Returns: the width of this image.

getX ​

getX(): intSince1.8.4#
Returns the x position where this image is drawn.
Returns: the x position of this image.

getY ​

getY(): intSince1.8.4#
Returns the y position where this image is drawn.
Returns: the y position of this image.

getZIndex ​

getZIndex(): int#
Returns this image's ordering value on its overlay; lower values are drawn first.
Returns: the z-index of this element

isRotatingCenter ​

isRotatingCenter(): booleanSince1.8.4#
Returns whether rotation is about the center of the destination rectangle.
Returns: true for the destination rectangle's center; false for the image position

moveTo ​

moveTo(int x, int y): Image#
Moves this image without changing its destination size.

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 this image as part of its overlay, applying its position, rotation, and tint. The mouse coordinates and frame delta are unused. The 2D draw uses the texture offset and destination size; it does not use the configured region width or height.

Parameters:

  • drawContext: the graphics context to draw into
  • mouseX: the mouse x, not used by this element
  • mouseY: the mouse y, not used by this element
  • delta: the frame delta, not used by this element

setColor ​

setColor(int color): ImageSince1.6.5#
Sets the packed ARGB tint. A zero alpha byte becomes opaque when RGB is nonzero; zero-alpha black remains transparent, and nonzero alpha is preserved.
const draw = Hud.createDraw2D();
const icon = draw.imageBuilder("minecraft:item/diamond").pos(10, 10).size(16, 16).buildAndAdd();
icon.setColor(Color.rgb(0xFF, 0x00, 0x00));
draw.register();
Chat.log(`0x${(icon.getColor() >>> 0).toString(16)}`); // ffff0000

Parameters:

  • color: packed ARGB colour, with alpha in the top byte
Returns: self for chaining
setColor(int color, int alpha): ImageSince1.6.5#
Sets the RGB tint with an explicit alpha byte, allowing transparent nonblack colours. Uses the low 24 bits of color and the low 8 bits of alpha; values outside 0..255 wrap rather than clamp, without changing the RGB bits.

Parameters:

  • color: packed RGB colour; its existing alpha byte is ignored
  • alpha: alpha from 0 (transparent) to 255 (opaque); only the low byte is used
Returns: self for chaining

setHeight ​

setHeight(int height): ImageSince1.8.4#
Sets the destination height, without changing the texture region. No range check is performed, so negative values are stored.

Parameters:

  • height: the new height of this image
Returns: self for chaining.

setImage ​

setImage(String id, int imageX, int imageY, int regionWidth, int regionHeight, int textureWidth, int textureHeight): ImageSince1.2.3#
sets the texture identifier, source offset, region size, and texture dimensions. The destination size is unchanged. On a 2D overlay, region dimensions are stored but ignored; the draw uses the offset, texture dimensions, and destination size.

Parameters:

  • id: the texture to draw from, with the namespace optional
  • imageX: the x position in the texture to start from
  • imageY: the y position in the texture to start from
  • regionWidth: the width of the region to take
  • regionHeight: the height of the region to take
  • textureWidth: the width of the whole texture
  • textureHeight: the height of the whole texture
Returns: self for chaining.

setParent ​

setParent(IDraw2D<?> parent): Image#
Sets the overlay used as this image's parent for parent-relative alignment. Passing null makes parent dimensions fall back to the window dimensions.

Parameters:

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

setPos ​

setPos(int x, int y): ImageSince1.8.4#
Sets both position coordinates without changing the size or texture.

Parameters:

  • x: the new x position of this image
  • y: the new y position of this image
Returns: self for chaining.
setPos(int x, int y, int width, int height): ImageSince1.2.3#
Sets the position and destination size; the texture region is unchanged.

Parameters:

  • x: the new x position of this image
  • y: the new y position of this image
  • width: the width to draw it at
  • height: the height to draw it at
Returns: self for chaining.

setRotateCenter ​

setRotateCenter(boolean rotateCenter): ImageSince1.8.4#
Sets whether rotation is about the center of the destination rectangle rather than the image position.

Parameters:

  • rotateCenter: whether the image should be rotated around its center
Returns: self for chaining

setRotation ​

setRotation(double rotation): ImageSince1.2.6#
Sets the rotation in degrees after converting to a float. Finite float values wrap to [-180, 180); setRotateCenter(boolean) selects the pivot.
const draw = Hud.createDraw2D();
const icon = draw.imageBuilder("minecraft:item/diamond").pos(20, 20).size(16, 16).buildAndAdd();
icon.setRotateCenter(true).setRotation(450);
draw.register();
Chat.log(`reads back as ${icon.getRotation()}`); // 90

Parameters:

  • rotation: the angle in degrees
Returns: self for chaining

setSize ​

setSize(int width, int height): ImageSince1.8.4#
Sets the destination width and height without changing the texture region. Negative values are stored without validation.

Parameters:

  • width: the width to draw it at
  • height: the height to draw it at
Returns: self for chaining.

setWidth ​

setWidth(int width): ImageSince1.8.4#
Sets the destination width, without changing the texture region. No range check is performed, so negative values are stored.

Parameters:

  • width: the new width of this image
Returns: self for chaining.

setX ​

setX(int x): ImageSince1.8.4#
Sets the x position without changing the y position or texture.

Parameters:

  • x: the new x position of this image
Returns: self for chaining.

setY ​

setY(int y): ImageSince1.8.4#
Sets the y position without changing the x position or texture.

Parameters:

  • y: the new y position of this image
Returns: self for chaining.

setZIndex ​

setZIndex(int zIndex): ImageSince1.8.4#
Sets this image's ordering value on its overlay; lower values are drawn first.

Parameters:

  • zIndex: the new z-index for this image
Returns: self for chaining.