CustomImage
com.jsmacrosce.jsmacros.client.api.classes.CustomImage
An image a script can draw on and hand to the game as a texture.
Drawing calls change the in-memory image; call update() to upload those pixels to its game texture. Updates upload the whole image, so they can be batched after several drawing calls.
Images register under minecraft:jsmimage/<name>; getIdentifier() returns that identifier. Creating another image with the same name registers it under the same identifier.
A script gets one through createWidget(int, int, String) for a blank one or createWidget(String, String) for one loaded from a file, and the class is available through the ScriptClasses.CustomImage type namespace.
// Draw several changes before uploading the image once.
const img = ScriptClasses.CustomImage.createWidget(16, 16, "badge");
img.setGraphicsColor(Color.rgb(0xFF, 0x55, 0x55));
img.fillRect(0, 0, 16, 16);
img.setGraphicsColor(Color.rgb(0xFF, 0xFF, 0xFF));
img.drawString(2, 11, "hi");
img.update();
Chat.log(`${img.getIdentifier()} is ${img.getWidth()} by ${img.getHeight()}`);Available in scripts as ScriptClasses.CustomImage.
Constructors
new CustomImage
Parameters:
image: the image to draw on and to hand to the game
jsmimage/ and parsed as a resource identifier, with the default minecraft namespace. Invalid identifier paths are rejected. The constructor registers and uploads the image before returning; an existing identifier is reused.Parameters:
image: the image to draw on and to hand to the gamename: the identifier-path name to register it under, without thejsmimage/prefix
Fields
IMAGES
null; creating an image with an existing identifier replaces that map entry. // Look up an image by its full identifier.
const made = ScriptClasses.CustomImage.createWidget(16, 16, "overlay");
const found = ScriptClasses.CustomImage.IMAGES.get(`minecraft:jsmimage/${made.getName()}`);
if (found !== null) {
Chat.log(`found the overlay at ${found.getWidth()} by ${found.getHeight()}`);
}Methods
clearRect
color argument to choose the background color for this operation.Parameters:
x: the x position of the rectangley: the y position of the rectanglewidth: the width of the rectangleheight: the height of the rectangle
color, then restores the previous graphics background.Parameters:
x: the x position of the rectangley: the y position of the rectanglewidth: the width of the rectangleheight: the height of the rectanglecolor: the rgb color to fill the rectangle with
clipRect
clipRect(int x, int y, int width, int height): CustomImage#Parameters:
x: the x coordinate of the rectangle to intersect the clip withy: the y coordinate of the rectangle to intersect the clip withwidth: the width of the rectangle to intersect the clip withheight: the height of the rectangle to intersect the clip with
copyArea
dx and dy are offsets from the source region's origin; overlapping source and destination regions are supported.Parameters:
x: the x position to copy fromy: the y position to copy fromwidth: the width of the area to copyheight: the height of the area to copydx: the offset to the x position to copy tody: the offset to the y position to copy to
createWidget
Parameters:
width: the width of the image in pixelsheight: the height of the image in pixelsname: the name to register it under, without thejsmimage/prefix
name is its game registration name, not the file name. Logs an error and returns null if reading fails or no image reader recognizes the file.Parameters:
path: the path to the image, relative to the jsMacros config foldername: the name to register it under, without thejsmimage/prefix
null if the file is unreadable or has an unsupported formatdraw3DRect
raised selects raised or etched shading.Parameters:
x: the x position to draw the 3D rectangle aty: the y position to draw the 3D rectangle atwidth: the width of the 3D rectangleheight: the height of the 3D rectangleraised: whether the rectangle should be raised above the surface or etched into the surface
drawArc
0 is at three o'clock and positive angles proceed anticlockwise.Parameters:
x: the x position to draw the arc aty: the y position to draw the arc atwidth: the width of the archeight: the height of the arcstartAngle: the beginning anglearcAngle: the angular extent of the arc, relative to the start angle
drawImage
Parameters:
img: the image to draw onto this imagex: the x position to draw the image aty: the y position to draw the image atwidth: the width of the image to drawheight: the height of the image to draw
drawImage(Image img, int x, int y, int width, int height, int sourceX, int sourceY, int sourceWidth, int sourceHeight): CustomImageSince1.8.4#(sourceX, sourceY, sourceWidth, sourceHeight) into the destination rectangle (x, y, width, height) on this image. The destination is scaled as needed; changes remain in memory until update() uploads them.Parameters:
img: the image to draw onto this imagex: the x position to draw the image aty: the y position to draw the image atwidth: the width of the image to drawheight: the height of the image to drawsourceX: the x position of the subimage to drawsourceY: the y position of the subimage to drawsourceWidth: the width of the subimage to drawsourceHeight: the height of the subimage to draw
drawLine
Parameters:
x1: the first x position of the liney1: the first y position of the linex2: the second x position of the liney2: the second y position of the line
drawOval
Parameters:
x: the x position to draw the oval aty: the y position to draw the oval atwidth: the width of the ovalheight: the height of the oval
drawPolygon
Parameters:
pointsX: an array of all x positions of the points in the polygonpointsY: an array of all y positions of the points in the polygon
drawPolygonLine
Parameters:
pointsX: an array of all x positions of the points in the polygonpointsY: an array of all y positions of the points in the polygon
drawRect
Parameters:
x: the x position of the rectangley: the y position of the rectanglewidth: the width of the rectangleheight: the height of the rectangle
drawRoundRect
drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight): CustomImageSince1.8.4#arcWidth and arcHeight specify the corner arc diameters.Parameters:
x: the x position to draw the rectangle aty: the y position to draw the rectangle atwidth: the width of the rectangleheight: the height of the rectanglearcWidth: the horizontal diameter of the arc at the four cornersarcHeight: the vertical diameter of the arc at the four corners
drawString
Parameters:
x: the x position to draw the string aty: the y position to draw the string attext: the text to draw
fill3DRect
raised selects raised or etched shading.Parameters:
x: the x position to draw the 3D rectangle aty: the y position to draw the 3D rectangle atwidth: the width of the 3D rectangleheight: the height of the 3D rectangleraised: whether the rectangle should be raised above the surface or etched into the surface
fillArc
0 is at three o'clock and positive angles proceed anticlockwise.Parameters:
x: the x position to draw the arc aty: the y position to draw the arc atwidth: the width of the archeight: the height of the arcstartAngle: the beginning anglearcAngle: the angular extent of the arc, relative to the start angle
fillOval
Parameters:
x: the x position to draw the oval aty: the y position to draw the oval atwidth: the width of the ovalheight: the height of the oval
fillPolygon
Parameters:
pointsX: an array of all x positions of the points in the polygonpointsY: an array of all y positions of the points in the polygon
fillRect
Parameters:
x: the x position of the rectangley: the y position of the rectanglewidth: the width of the rectangleheight: the height of the rectangle
fillRoundRect
fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight): CustomImageSince1.8.4#arcWidth and arcHeight specify the corner arc diameters.Parameters:
x: the x position to draw the rectangle aty: the y position to draw the rectangle atwidth: the width of the rectangleheight: the height of the rectanglearcWidth: the horizontal diameter of the arc at the four cornersarcHeight: the vertical diameter of the arc at the four corners
getClipBounds
getGraphicsColor
getHeight
getIdentifier
getImage
getName
getPixel
(x, y) as an ARGB integer. Coordinates outside the image are rejected by the underlying image implementation.Parameters:
x: the x position to get the color fromy: the y position to get the color from
getStringWidth
getWidth
loadImage
null if reading fails or no image reader recognizes the file; I/O exceptions are logged. The result is an ordinary BufferedImage, not a registered game texture. // Load an image file and draw it when recognized.
const img = ScriptClasses.CustomImage.createWidget(32, 32, "canvas");
const source = img.loadImage("images/logo.png");
if (source !== null) {
img.drawImage(source, 0, 0, 32, 32);
img.update();
}Parameters:
path: the path to the image, relative to the jsMacros config folder
null if the file could not be read or is not an imagenull, as in loadImage(String). Coordinates are measured from the image's top-left; an invalid crop, including one outside the image, throws RasterFormatException. The returned subimage shares pixel data with the loaded image.Parameters:
path: the path to the image, relative to the jsMacros config folderx: the x position to get the subimage fromy: the y position to get the subimage fromwidth: the width of the subimageheight: the height of the subimage
null if the file could not be read or is not an imagenativeARGBFlip
argb with its red and blue bytes exchanged; the alpha and green bytes are unchanged. This arithmetic helper does not modify an image.Parameters:
argb: the ARGB value to transform
saveImage
.png is appended to fileName, and an existing file is overwritten. I/O failures are logged rather than thrown; the returned value does not indicate whether writing succeeded. This saves the in-memory image, whether or not update() has uploaded recent changes.Parameters:
path: the path to the image, relative to the jsMacros config folderfileName: the file name of the image, without the extension
setClip
Parameters:
x: the x coordinate of the new clip rectangley: the y coordinate of the new clip rectanglewidth: the width of the new clip rectangleheight: the height of the new clip rectangle
setGraphicsColor
color are ignored; this does not set the background used by clearRect(int, int, int, int).Parameters:
color: the rgb color to use for graphics operations
setPaintMode
setPixel
Parameters:
x: the x position to set the color aty: the y position to set the color atargb: the ARGB value to set the pixel to
setXorMode
color as the XOR color. The mode remains active until setPaintMode() is called.Parameters:
color: the color to use for the xor operation
translate
Parameters:
x: the x position of the origin pointy: the y position of the origin point