Draw3D
com.jsmacrosce.jsmacros.client.api.classes.render.Draw3D
A collection of 3D elements rendered as a world overlay.
Elements use world-space block coordinates and are rendered relative to the camera.
Elements render only while this overlay is registered with register() and visible; unregister() stops rendering without removing them, while clear() removes its elements.
Duplicate entries are allowed. Elements are sorted in place before rendering, so typed getters return matching entries in the current sorted order, not insertion order.
// a world overlay with a box and a line in it, registered so it shows
const draw = Hud.createDraw3D();
draw.addBox(0, 64, 0, 1, 65, 1, Color.rgb(0xFF, 0x00, 0x00), Color.argb(0x88, 0, 0, 0), true);
draw.addLine(0, 64, 0, 8, 72, 0, Color.rgb(0x00, 0xFF, 0x00));
draw.register();
// what went in, in the order it will be drawn
Chat.log(`${draw.getBoxes().size()} boxes, ${draw.getLines().size()} lines`);
// stop rendering this overlay without removing its elements
draw.unregister();Constructors
new Draw3D
new Draw3D()#Fields
visible
true. Use setVisible(boolean) to change it.Methods
addBox
Parameters:
box: the cube to add
addBox(double x1, double y1, double z1, double x2, double y2, double z2, int color, int fillColor, boolean fill): BoxSince1.0.6#Parameters:
x1: the x coordinate of the first cornery1: the y coordinate of the first cornerz1: the z coordinate of the first cornerx2: the x coordinate of the second cornery2: the y coordinate of the second cornerz2: the z coordinate of the second cornercolor: the colour of the outline, with or without an alpha of its ownfillColor: the colour of the insidefill: whether to draw the inside as well as the outline
addBox(double x1, double y1, double z1, double x2, double y2, double z2, int color, int fillColor, boolean fill, boolean cull): BoxSince1.3.1#Parameters:
x1: the x coordinate of the first cornery1: the y coordinate of the first cornerz1: the z coordinate of the first cornerx2: the x coordinate of the second cornery2: the y coordinate of the second cornerz2: the z coordinate of the second cornercolor: the colour of the outline, with or without an alpha of its ownfillColor: the colour of the insidefill: whether to draw the inside as well as the outlinecull: whether to depth-test the box against world geometry;falsedraws over it
addBox(double x1, double y1, double z1, double x2, double y2, double z2, int color, int alpha, int fillColor, int fillAlpha, boolean fill): BoxSince1.1.8#Parameters:
x1: the x coordinate of the first cornery1: the y coordinate of the first cornerz1: the z coordinate of the first cornerx2: the x coordinate of the second cornery2: the y coordinate of the second cornerz2: the z coordinate of the second cornercolor: the colour of the outlinealpha: the alpha of the outline, from 0 to 255fillColor: the colour of the insidefillAlpha: the alpha of the inside, from 0 to 255fill: whether to draw the inside as well as the outline
addBox(double x1, double y1, double z1, double x2, double y2, double z2, int color, int alpha, int fillColor, int fillAlpha, boolean fill, boolean cull): BoxSince1.3.1#cull enables depth testing so terrain can occlude the box. Without this argument, depth testing is disabled.Parameters:
x1: the x coordinate of the first cornery1: the y coordinate of the first cornerz1: the z coordinate of the first cornerx2: the x coordinate of the second cornery2: the y coordinate of the second cornerz2: the z coordinate of the second cornercolor: the colour of the outlinealpha: the alpha of the outline, from 0 to 255fillColor: the colour of the insidefillAlpha: the alpha of the inside, from 0 to 255fill: whether to draw the inside as well as the outlinecull: whether the box is depth tested, so terrain draws over it
addDraw2D
Parameters:
x: the x coordinate of the panel cornery: the y coordinate of the panel cornerz: the z coordinate of the panel corner
Parameters:
x: the x coordinate of the panel's cornery: the y coordinate of the panel's cornerz: the z coordinate of the panel's cornerwidth: the width of the panel, in blocksheight: the height of the panel, in blocks
Parameters:
x: the x coordinate of the panel's cornery: the y coordinate of the panel's cornerz: the z coordinate of the panel's cornerxRot: the rotation about the x axis, in degreesyRot: the rotation about the y axis, in degreeszRot: the rotation about the z axis, in degrees
addDraw2D(double x, double y, double z, double xRot, double yRot, double zRot, double width, double height): SurfaceSince1.6.5#Parameters:
x: the x coordinate of the panel's cornery: the y coordinate of the panel's cornerz: the z coordinate of the panel's cornerxRot: the rotation about the x axis, in degreesyRot: the rotation about the y axis, in degreeszRot: the rotation about the z axis, in degreeswidth: the width of the panel, in blocksheight: the height of the panel, in blocks
addDraw2D(double x, double y, double z, double xRot, double yRot, double zRot, double width, double height, int minSubdivisions): SurfaceSince1.6.5#Parameters:
x: the x coordinate of the panel's cornery: the y coordinate of the panel's cornerz: the z coordinate of the panel's cornerxRot: the rotation about the x axis, in degreesyRot: the rotation about the y axis, in degreeszRot: the rotation about the z axis, in degreeswidth: the width of the panel, in blocksheight: the height of the panel, in blocksminSubdivisions: the minimum number of subdivisions along the shorter side
addDraw2D(double x, double y, double z, double xRot, double yRot, double zRot, double width, double height, int minSubdivisions, boolean renderBack): SurfaceSince1.6.5#Parameters:
x: the x coordinate of the panel's cornery: the y coordinate of the panel's cornerz: the z coordinate of the panel's cornerxRot: the rotation about the x axis, in degreesyRot: the rotation about the y axis, in degreeszRot: the rotation about the z axis, in degreeswidth: the width of the panel, in blocksheight: the height of the panel, in blocksminSubdivisions: the minimum number of subdivisions along the shorter siderenderBack: whether the back of the panel is drawn as well as its front
addDraw2D(double x, double y, double z, double xRot, double yRot, double zRot, double width, double height, int minSubdivisions, boolean renderBack, boolean cull): SurfaceSince1.6.5#Parameters:
x: the x coordinate of the panel cornery: the y coordinate of the panel cornerz: the z coordinate of the panel cornerxRot: the rotation about the x axis, in degreesyRot: the rotation about the y axis, in degreeszRot: the rotation about the z axis, in degreeswidth: the width of the panel, in blocksheight: the height of the panel, in blocksminSubdivisions: the minimum number of subdivisions along the shorter siderenderBack: whether the back of the panel is drawn as well as its frontcull: whether to depth-test the panel against world geometry;falsedraws over it
addEntityTraceLine
Parameters:
entity: the entity to point atcolor: the colour of the line
Parameters:
entity: the entity to point atcolor: the colour of the linealpha: the alpha of the line, from 0 to 255
addEntityTraceLine(EntityHelper<?> entity, int color, int alpha, double yOffset): EntityTraceLineSince1.9.0#const player = Player.getPlayer();
if (player !== null) {
const draw = Hud.createDraw3D();
// aim at the player's eyes rather than their feet
draw.addEntityTraceLine(player, Color.rgb(0xFF, 0x00, 0x00), 255, player.getEyeHeight());
draw.register();
}Parameters:
entity: the entity to point atcolor: the colour of the linealpha: the alpha of the line, from 0 to 255yOffset: how far above the entity's feet to aim, in blocks
addEntityTraceLine(EntityHelper<?> entity, int color, int alpha, double yOffset, boolean alwaysOnTop): EntityTraceLineSince1.9.0#alwaysOnTop to true to draw it over the world; false allows terrain to hide it.Parameters:
entity: the entity to point atcolor: the colour of the linealpha: the alpha of the line, from 0 to 255yOffset: how far above the entity's feet to aim, in blocksalwaysOnTop: whether to draw over the world instead of allowing terrain to hide the line
addLine
Parameters:
line: the line to add
addLine(double x1, double y1, double z1, double x2, double y2, double z2, int color): Line3DSince1.0.6#Parameters:
x1: the x coordinate of the starty1: the y coordinate of the startz1: the z coordinate of the startx2: the x coordinate of the endy2: the y coordinate of the endz2: the z coordinate of the endcolor: the line color, with or without an alpha byte
addLine(double x1, double y1, double z1, double x2, double y2, double z2, int color, boolean cull): Line3DSince1.3.1#cull false, it draws over the world.Parameters:
x1: the x coordinate of the starty1: the y coordinate of the startz1: the z coordinate of the startx2: the x coordinate of the endy2: the y coordinate of the endz2: the z coordinate of the endcolor: the colour of the line, with or without an alpha of its owncull: whether to depth-test the line against world geometry
addLine(double x1, double y1, double z1, double x2, double y2, double z2, int color, int alpha): Line3DSince1.1.8#Parameters:
x1: the x coordinate of the starty1: the y coordinate of the startz1: the z coordinate of the startx2: the x coordinate of the endy2: the y coordinate of the endz2: the z coordinate of the endcolor: the colour of the linealpha: the alpha of the line, from 0 to 255
addLine(double x1, double y1, double z1, double x2, double y2, double z2, int color, int alpha, boolean cull): Line3DSince1.3.1#Parameters:
x1: the x coordinate of the starty1: the y coordinate of the startz1: the z coordinate of the startx2: the x coordinate of the endy2: the y coordinate of the endz2: the z coordinate of the endcolor: the colour of the linealpha: the alpha of the line, from 0 to 255cull: whether to depth-test the line against world geometry
addPoint
point, with side length twice the radius.Parameters:
point: the center pointradius: 1/2 of the side length of the cubecolor: point color
See:
Parameters:
x: x value of the center pointy: y value of the center pointz: z value of the center pointradius: 1/2 of the side length of the cubecolor: point color
See:
addPoint(double x, double y, double z, double radius, int color, int alpha, boolean cull): BoxSince1.4.0#cull controls whether terrain can hide it.Parameters:
x: x value of the center pointy: y value of the center pointz: z value of the center pointradius: 1/2 of the side length of the cubecolor: point coloralpha: alpha of the point, used for both the outline and the insidecull: whether to cull the point or not
See:
addSurface
addTraceLine
Parameters:
line: the trace line to add
Parameters:
x: the x coordinate of the targety: the y coordinate of the targetz: the z coordinate of the targetcolor: the colour of the line
Parameters:
x: the x coordinate of the targety: the y coordinate of the targetz: the z coordinate of the targetcolor: the colour of the linealpha: the alpha of the line, from 0 to 255
pos do not move the target; the line draws over terrain by default.Parameters:
pos: the position of the targetcolor: the colour of the line
Parameters:
pos: the position of the targetcolor: the colour of the linealpha: the alpha of the line, from 0 to 255
boxBuilder
const draw = Hud.createDraw3D();
draw.boxBuilder().pos(0, 64, 0, 3, 67, 2).color(Color.rgb(0xFF, 0x00, 0x00)).buildAndAdd();
draw.register();const player = Player.getPlayer();
if (player !== null) {
const draw = Hud.createDraw3D();
draw.boxBuilder(player.getBlockPos()).color(Color.rgb(0xFF, 0x00, 0x00)).buildAndAdd();
draw.register();
}Parameters:
pos: the block position of the box
(x, y, z). const draw = Hud.createDraw3D();
// a wireframe around a single block
draw.boxBuilder(0, 64, 0).color(Color.rgb(0xFF, 0x00, 0x00)).buildAndAdd();
draw.register();Parameters:
x: the x coordinate of the boxy: the y coordinate of the boxz: the z coordinate of the box
clear
entityTraceLineBuilder
0.5-block vertical offset. No entity is set by default; a line built without one is removed on its first frame. const player = Player.getPlayer();
if (player !== null) {
const draw = Hud.createDraw3D();
draw.entityTraceLineBuilder().entity(player).color(Color.rgb(0xFF, 0x00, 0x00)).buildAndAdd();
draw.register();
}getBoxes
getDraw2Ds
getElements
getEntityTraceLines
getLines
getTraceLines
isVisible
true if this overlay is visible; false otherwiselineBuilder
const draw = Hud.createDraw3D();
draw.lineBuilder().pos(0, 64, 0, 8, 72, 0).color(Color.rgb(0x00, 0xFF, 0x00)).buildAndAdd();
draw.register();reAddElement
build() are not added automatically; adding the same instance more than once creates duplicate list entries and draws it more than once.Parameters:
element: the element to put back
Type Parameters:
T: the type of element to add
register
const draw = Hud.createDraw3D();
draw.addBox(0, 64, 0, 1, 65, 1, Color.rgb(0xFF, 0x00, 0x00), Color.argb(0, 0, 0, 0), false);
// nothing has been drawn until this
draw.register();removeBox
removeDraw2D
removeElement
Parameters:
element: the element to take off
removeLine
removeTraceLine
setVisible
surfaceBuilder
10 × 10-block size, centered rotation, a rendered back, no depth culling, and full-bright lighting. Its default subdivision count is 1, so set the size and subdivisions for the desired panel dimensions and element resolution. const draw = Hud.createDraw3D();
const surface = draw.surfaceBuilder()
.pos(0.5, 64, 0.5)
.size(1, 1)
.minSubdivisions(200)
.buildAndAdd();
surface.addText("hello", 10, 10, Color.rgb(0xFF, 0xFF, 0xFF), true);
draw.register();traceLineBuilder
const draw = Hud.createDraw3D();
draw.traceLineBuilder().pos(0, 64, 0).color(Color.rgb(0xFF, 0x00, 0x00)).buildAndAdd();
draw.register();unregister
const draw = Hud.createDraw3D();
draw.addBox(0, 64, 0, 1, 65, 1, Color.rgb(0xFF, 0x00, 0x00), Color.argb(0, 0, 0, 0), false);
draw.register();
draw.unregister();
// the box is still on the overlay, just not being drawn
Chat.log(`${draw.getBoxes().size()} boxes, none of them visible`);