Skip to content

Box ​

com.jsmacrosce.jsmacros.client.api.classes.render.components3d.Box

Since1.0.6

An axis-aligned cuboid with an outline and an optional filled interior. Its position is defined by two opposite corners, and its outline and fill have independent colours.
Setters taking a packed colour make a zero alpha byte opaque unless the whole value is zero; overloads taking a separate alpha preserve zero alpha.

cull enables depth testing, allowing terrain to hide the box; otherwise it is drawn over the world. Builders and Draw3D helpers default it to false.

js
const draw = Hud.createDraw3D();  
// a filled red cube one block on a side, drawn over the world
draw.addBox(0, 64, 0, 1, 65, 1, Color.rgb(0xFF, 0x00, 0x00), Color.argb(0x88, 0, 0, 0), true);  
draw.register();

Available in scripts as RenderElements.Box.

Nested types ​

Constructors ​

new Box ​

new Box(double x1, double y1, double z1, double x2, double y2, double z2, int color, int fillColor, boolean fill, boolean cull)#
Constructs a detached box from two ordered opposite corners in world-space block coordinates and packed outline and fill colours. For each colour, a nonzero RGB value with a zero alpha byte becomes opaque, while zero remains transparent. This does not add or register the box with a Draw3D overlay.

Parameters:

  • x1: x coordinate of the first corner
  • y1: y coordinate of the first corner
  • z1: z coordinate of the first corner
  • x2: x coordinate of the opposite corner
  • y2: y coordinate of the opposite corner
  • z2: z coordinate of the opposite corner
  • color: packed outline colour
  • fillColor: packed fill colour
  • fill: whether to draw the interior
  • cull: whether to enable the renderer's depth-testing setting
new Box(double x1, double y1, double z1, double x2, double y2, double z2, int color, int alpha, int fillColor, int fillAlpha, boolean fill, boolean cull)#
Constructs a detached box from two ordered opposite corners in world-space block coordinates, with outline and fill alpha supplied separately. Each colour's existing alpha byte is ignored; its low 24 bits are combined with the corresponding alpha using a left shift, without range validation. This does not add or register the box with an overlay.

Parameters:

  • x1: x coordinate of the first corner
  • y1: y coordinate of the first corner
  • z1: z coordinate of the first corner
  • x2: x coordinate of the opposite corner
  • y2: y coordinate of the opposite corner
  • z2: z coordinate of the opposite corner
  • color: outline RGB value; its top byte is ignored
  • alpha: outline alpha, shifted into the top byte without range validation
  • fillColor: fill RGB value; its top byte is ignored
  • fillAlpha: fill alpha, shifted into the top byte without range validation
  • fill: whether to draw the interior
  • cull: whether to enable the renderer's depth-testing setting

Fields ​

color ​

color: intSince1.0.6#
The outline colour, packed with alpha in the top byte. The outline is drawn whether or not fill is set.

cull ​

cull: booleanSince1.0.6#
Whether this box is depth tested, allowing terrain to hide it; false draws it over the world.

fill ​

fill: booleanSince1.0.6#
Whether to draw the inside as well as the outline.

fillColor ​

fillColor: intSince1.0.6#
The fill colour, packed the same way as color; used only when fill is true.

pos ​

pos: Vec3DSince1.0.6#
The two opposite corners defining this box. Their supplied order is retained.

Methods ​

compareToSame ​

compareToSame(Box other): intSince1.8.4#
Compares this box's corner coordinates lexicographically with another box's. The comparison is not based on distance or overlap; colour, fill, and culling do not affect the result.

Parameters:

  • other: another box to order this one against
Returns: a negative number, zero, or a positive number as this box is before, the same as, or after other

equals ​

equals(Object o): boolean#
Tests equality by exact runtime class and current position value; colour, fill, and depth-testing settings are ignored. A null argument or a different class does not match; null positions compare equal to null positions.

Parameters:

  • o: object to compare
Returns: true if the objects match by this rule

hashCode ​

hashCode(): int#
Computes a hash from the current position only. Since position is mutable, the hash may change when it changes; colour, fill, and depth-testing settings are ignored.
Returns: hash of the current position

setAlpha ​

setAlpha(int alpha): voidSince1.1.8#
Replaces the outline alpha without changing its RGB or the fill colour.

Parameters:

  • alpha: the alpha of the outline, from 0 to 255

setColor ​

setColor(int color): voidSince1.0.6#
Replaces the outline colour. If its alpha byte is zero but its RGB value is nonzero, the alpha is made opaque; transparent black remains transparent. Use setColor(int, int) to specify zero alpha explicitly.

Parameters:

  • color: the colour of the outline
setColor(int color, int alpha): voidSince1.1.8#
Sets the outline RGB and alpha explicitly. The alpha replaces the top byte; zero remains transparent.

Parameters:

  • color: the colour of the outline
  • alpha: the alpha of the outline, from 0 to 255

setFill ​

setFill(boolean fill): voidSince1.0.6#
Controls whether the interior is drawn; disabling it leaves the outline unchanged.

Parameters:

  • fill: whether to draw the inside as well as the outline

setFillAlpha ​

setFillAlpha(int alpha): voidSince1.1.8#
Replaces the fill alpha without changing its RGB. It is visible only when fill is true.

Parameters:

  • alpha: the alpha of the inside, from 0 to 255

setFillColor ​

setFillColor(int fillColor): voidSince1.0.6#
Replaces the fill colour using the same zero-alpha handling as setColor(int). The colour is stored even while filling is disabled.

Parameters:

  • fillColor: the colour of the inside
setFillColor(int fillColor, int alpha): voidSince1.1.8#
Sets the fill RGB and alpha explicitly, preserving zero alpha. It is visible only when fill is true.

Parameters:

  • fillColor: the colour of the inside
  • alpha: the alpha of the inside, from 0 to 255

setPos ​

setPos(double x1, double y1, double z1, double x2, double y2, double z2): voidSince1.0.6#
Replaces pos with the supplied opposite corners, retaining their order.

Parameters:

  • x1: the x coordinate of the first corner
  • y1: the y coordinate of the first corner
  • z1: the z coordinate of the first corner
  • x2: the x coordinate of the second corner
  • y2: the y coordinate of the second corner
  • z2: the z coordinate of the second corner

setPosToBlock ​

setPosToBlock(BlockPosHelper pos): voidSince1.9.0#
Sets this box to cover the block at pos, extending one block from its coordinates along each axis.

Parameters:

  • pos: the block to cover
setPosToBlock(int x, int y, int z): voidSince1.9.0#
Sets this box to cover the block at the given coordinates, extending one block from that corner along each axis.

Parameters:

  • x: the x coordinate of the block's corner
  • y: the y coordinate of the block's corner
  • z: the z coordinate of the block's corner

setPosToPoint ​

setPosToPoint(Pos3D pos, double radius): voidSince1.9.0#
Sets this box to a cube centred on pos, with side length twice radius.

Parameters:

  • pos: the centre of the cube
  • radius: half the side length, in blocks
setPosToPoint(double x, double y, double z, double radius): voidSince1.9.0#
Sets this box to a cube centred on the given point, with side length twice radius. A negative radius reverses the supplied corner order.

Parameters:

  • x: the x coordinate of the centre
  • y: the y coordinate of the centre
  • z: the z coordinate of the centre
  • radius: half the side length, in blocks