Image
com.jsmacrosce.jsmacros.client.api.classes.render.components.Image
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 imagey: the y position of the imagewidth: the width the piece is drawn atheight: the height the piece is drawn atzIndex: the z-index against the other elements on the overlaycolor: the tint, with the alpha in the top byteid: the texture to draw from, with the namespace optionalimageX: the x position in the texture to start fromimageY: the y position in the texture to start fromregionWidth: the width of the region to takeregionHeight: the height of the region to taketextureWidth: the width of the whole texturetextureHeight: the height of the whole texturerotation: 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 imagey: the y position of the imagewidth: the width the piece is drawn atheight: the height the piece is drawn atzIndex: the z-index against the other elements on the overlayalpha: the alpha, in the top bytecolor: the colour, whose top byte is replacedid: the texture to draw from, with the namespace optionalimageX: the x position in the texture to start fromimageY: the y position in the texture to start fromregionWidth: the width of the region to takeregionHeight: the height of the region to taketextureWidth: the width of the whole texturetextureHeight: the height of the whole texturerotation: 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
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
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 255getColor
Returns the packed tint currently stored by this image, with alpha in the top byte.
Returns: the packed ARGB tint
getHeight
Returns the destination height, independent of the texture region.
Returns: the height of this image.
getImage
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
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
Returns the destination width, which is independent of the texture region.
Returns: the width of this image.
getX
Returns the x position where this image is drawn.
Returns: the x position of this image.
getY
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
Returns whether rotation is about the center of the destination rectangle.
Returns:
true for the destination rectangle's center; false for the image positionmoveTo
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 intomouseX: the mouse x, not used by this elementmouseY: the mouse y, not used by this elementdelta: the frame delta, not used by this element
setColor
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)}`); // ffff0000Parameters:
color: packed ARGB colour, with alpha in the top byte
Returns: self for chaining
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 ignoredalpha: alpha from0(transparent) to255(opaque); only the low byte is used
Returns: self for chaining
setHeight
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 optionalimageX: the x position in the texture to start fromimageY: the y position in the texture to start fromregionWidth: the width of the region to takeregionHeight: the height of the region to taketextureWidth: the width of the whole texturetextureHeight: the height of the whole texture
Returns: self for chaining.
setParent
setPos
Sets both position coordinates without changing the size or texture.
Parameters:
x: the new x position of this imagey: the new y position of this image
Returns: self for chaining.
Sets the position and destination size; the texture region is unchanged.
Parameters:
x: the new x position of this imagey: the new y position of this imagewidth: the width to draw it atheight: the height to draw it at
Returns: self for chaining.
setRotateCenter
setRotation
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()}`); // 90Parameters:
rotation: the angle in degrees
Returns: self for chaining