Skip to content

Box.Builder ​

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

Since1.8.4

Configures a Box before building it. build() returns the box without adding it; buildAndAdd() adds it to the originating overlay.
The default is a zero-size box at the origin with opaque white outline and fill colours, no fill, and no depth testing.

Use forBlock(int, int, int) for a one-block box or the corner setters to specify arbitrary bounds.

js
const draw = Hud.createDraw3D();  
draw.boxBuilder(0, 64, 0)
  .color(Color.rgb(0xFF, 0x00, 0x00))
  .fillColor(Color.rgb(0x00, 0xFF, 0x00), 128)
  .fill(true)
  .cull(true)
  .buildAndAdd();  
draw.register();

Nested type declared in Box.

Constructors ​

new Box.Builder ​

new Box.Builder(Draw3D parent)#
Creates a builder with coincident origin corners, opaque white outline and fill, filling disabled, and depth testing disabled. Construction does not build or add a box. A null parent is acceptable for build(), but buildAndAdd() throws NullPointerException when it tries to add to that parent.

Parameters:

  • parent: overlay used by buildAndAdd(); may be null when only building detached boxes

Methods ​

alpha ​

alpha(int alpha): Box.BuilderSince1.8.4#
Sets the outline alpha independently of its colour; a later colour setter that accepts alpha may replace it. The fill alpha is separate.

Parameters:

  • alpha: the alpha value for the box's color
Returns: self for chaining.

build ​

build(): Box#
Builds a new box from the current builder values without adding it to an overlay. Later builder changes do not modify the returned box.
Returns: the build box.

buildAndAdd ​

buildAndAdd(): BoxSince1.8.4#
Builds the box and adds it to the parent overlay.
Returns: the build box.

color ​

color(int color): Box.BuilderSince1.8.4#
Sets the outline colour and derives its alpha from the packed value, making a zero alpha byte opaque for non-black colours.

Parameters:

  • color: the color of the box
Returns: self for chaining.
color(int color, int alpha): Box.BuilderSince1.8.4#
Sets the outline colour and alpha separately; the colour is stored unchanged, including any alpha byte, which is ignored when building the box's outline.

Parameters:

  • color: the color of the box
  • alpha: the alpha value for the box's color
Returns: self for chaining.
color(int r, int g, int b): Box.BuilderSince1.8.4#
Packs the components with shifts and bitwise OR, without clamping or masking; leaves the separately stored outline alpha unchanged.

Parameters:

  • r: the red component of the color
  • g: the green component of the color
  • b: the blue component of the color
Returns: self for chaining.
color(int r, int g, int b, int a): Box.BuilderSince1.8.4#
Packs RGB as in color(int, int, int) and stores alpha separately.

Parameters:

  • r: the red component of the color
  • g: the green component of the color
  • b: the blue component of the color
  • a: the alpha component of the color
Returns: self for chaining.

cull ​

cull(boolean cull): Box.BuilderSince1.8.4#
Enables depth testing, allowing terrain to hide the box; defaults to false, which draws it over the world.

Parameters:

  • cull: whether to enable culling or not
Returns: self for chaining.

fill ​

fill(boolean fill): Box.BuilderSince1.8.4#
Controls whether the inside is drawn; it defaults to false.

Parameters:

  • fill: true if the box should be filled, false otherwise
Returns: self for chaining.

fillAlpha ​

fillAlpha(int fillAlpha): Box.BuilderSince1.8.4#
Sets the separate fill alpha without changing the fill colour or outline.

Parameters:

  • fillAlpha: the alpha value for the box's fill color
Returns: self for chaining.

fillColor ​

fillColor(int fillColor): Box.BuilderSince1.8.4#
Stores the colour and sets the separate fill alpha from its alpha byte; a non-black colour with zero alpha is made opaque.

Parameters:

  • fillColor: the fill color of the box
Returns: self for chaining.
fillColor(int fillColor, int alpha): Box.BuilderSince1.8.4#
Stores the colour and alpha separately from the outline; the colour is kept exactly as given, including any alpha byte in it.

Parameters:

  • fillColor: the fill color of the box
  • alpha: the alpha value for the box's fill color
Returns: self for chaining.
fillColor(int r, int g, int b): Box.BuilderSince1.8.4#
Packs the RGB components without clamping or masking them; this does not change the separately stored fill alpha or the outline.

Parameters:

  • r: the red component of the fill color
  • g: the green component of the fill color
  • b: the blue component of the fill color
Returns: self for chaining.
fillColor(int r, int g, int b, int a): Box.BuilderSince1.8.4#
Packs RGB without clamping or masking and stores alpha separately from the outline.

Parameters:

  • r: the red component of the fill color
  • g: the green component of the fill color
  • b: the blue component of the fill color
  • a: the alpha component of the fill color
Returns: self for chaining.

forBlock ​

forBlock(int x, int y, int z): Box.BuilderSince1.8.4#
Sets both corners to cover the block at these coordinates, from its corner to one block further along each axis. This replaces any previously set corners.

Parameters:

  • x: the x coordinate of the block
  • y: the y coordinate of the block
  • z: the z coordinate of the block
Returns: self for chaining.
forBlock(BlockPosHelper pos): Box.BuilderSince1.8.4#
Sets both corners to cover the block named by this position, from its integer coordinates to one block further along each axis; the position's offset is not used.
const player = Player.getPlayer();
if (player !== null) {
  const draw = Hud.createDraw3D();
  draw.boxBuilder().forBlock(player.getBlockPos()).color(Color.rgb(0xFF, 0x00, 0x00)).buildAndAdd();
  draw.register();
}

Parameters:

  • pos: the block position
Returns: self for chaining.

getAlpha ​

getAlpha(): intSince1.8.4#
Returns the separately stored outline alpha; it is independent of the fill alpha.
Returns: the alpha value of the box's color.

getColor ​

getColor(): intSince1.8.4#
Returns the stored outline colour, which may retain an alpha byte even though the built box uses the separately stored alpha.
Returns: the color of the box.

getFillAlpha ​

getFillAlpha(): intSince1.8.4#
Returns the separately stored fill alpha, initially 255; outline alpha changes do not affect it.
Returns: the alpha value of the box's fill color.

getFillColor ​

getFillColor(): intSince1.8.4#
Returns the stored fill colour, which may include an alpha byte; the built box combines this value with the separately stored fill alpha.
Returns: the fill color of the box.

getPos1 ​

getPos1(): Pos3DSince1.8.4#
Returns the builder's first-corner object; mutating it affects boxes built later.
Returns: the first position of the box.

getPos2 ​

getPos2(): Pos3DSince1.8.4#
Returns the builder's second-corner object; mutating it affects boxes built later.
Returns: the second position of the box.

isCulled ​

isCulled(): booleanSince1.8.4#
Returns whether this builder enables depth testing, allowing terrain to hide the box. The default is false.
Returns: true if culling is enabled for this box, false otherwise.

isFilled ​

isFilled(): booleanSince1.8.4#
Returns whether the builder enables drawing the box's inside.
Returns: true if the box should be filled, false otherwise.

pos ​

pos(double x1, double y1, double z1, double x2, double y2, double z2): Box.BuilderSince1.8.4#
Sets both opposite corners, creating new position objects rather than retaining references supplied by the caller.

Parameters:

  • x1: the x coordinate of the first position of the box
  • y1: the y coordinate of the first position of the box
  • z1: the z coordinate of the first position of the box
  • x2: the x coordinate of the second position of the box
  • y2: the y coordinate of the second position of the box
  • z2: the z coordinate of the second position of the box
Returns: self for chaining.
pos(BlockPosHelper pos1, BlockPosHelper pos2): Box.BuilderSince1.8.4#
Sets both corners from the block positions' integer coordinates, converting each helper to a position object.

Parameters:

  • pos1: the first position of the box
  • pos2: the second position of the box
Returns: self for chaining.
pos(Pos3D pos1, Pos3D pos2): Box.BuilderSince1.8.4#
Stores both position objects by reference in the builder. Mutating either affects a later build; an already-built box copies their coordinate values.
const draw = Hud.createDraw3D();
const corner = PositionCommon.createPos(0, 64, 0);
draw.boxBuilder().pos(corner, PositionCommon.createPos(1, 65, 1)).buildAndAdd();
// moving the corner after the fact moves the box with it
corner.z = 8;
draw.register();

Parameters:

  • pos1: the first position of the box
  • pos2: the second position of the box
Returns: self for chaining.

pos1 ​

pos1(Pos3D pos1): Box.BuilderSince1.8.4#
Sets the first of the box's opposite corners. The position is stored by reference, so mutating it affects boxes built later, not boxes already built.

Parameters:

  • pos1: the first position of the box
Returns: self for chaining.
pos1(BlockPosHelper pos1): Box.BuilderSince1.8.4#
Sets the first corner from the block's integer coordinates; a second corner is still required to define the box.

Parameters:

  • pos1: the first position of the box
Returns: self for chaining.
pos1(double x1, double y1, double z1): Box.BuilderSince1.8.4#
Sets the first corner; use forBlock(int, int, int) to set both corners for a single block.

Parameters:

  • x1: the x coordinate of the first position of the box
  • y1: the y coordinate of the first position of the box
  • z1: the z coordinate of the first position of the box
Returns: self for chaining.

pos2 ​

pos2(Pos3D pos2): Box.BuilderSince1.8.4#
Sets the corner opposite pos1(double, double, double). The position is stored by reference, so mutating it affects boxes built later, not boxes already built.

Parameters:

  • pos2: the second position of the box
Returns: self for chaining.
pos2(BlockPosHelper pos2): Box.BuilderSince1.8.4#
Sets the opposite corner from the block's integer coordinates; unlike pos2(double, double, double), this converts the helper to a position object before storing it.

Parameters:

  • pos2: the second position of the box
Returns: self for chaining.
pos2(double x2, double y2, double z2): Box.BuilderSince1.8.4#
Sets the opposite corner; together with the first corner it determines the box, and either corner may be first.

Parameters:

  • x2: the x coordinate of the second position of the box
  • y2: the y coordinate of the second position of the box
  • z2: the z coordinate of the second position of the box
Returns: self for chaining.