Box.Builder
com.jsmacrosce.jsmacros.client.api.classes.render.components3d.Box.Builder
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
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
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
buildAndAdd
color
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.
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 boxalpha: the alpha value for the box's color
Returns: self for chaining.
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 colorg: the green component of the colorb: the blue component of the color
Returns: self for chaining.
Packs RGB as in color(int, int, int) and stores alpha separately.
Parameters:
r: the red component of the colorg: the green component of the colorb: the blue component of the colora: the alpha component of the color
Returns: self for chaining.
cull
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
Controls whether the inside is drawn; it defaults to
false.Parameters:
fill:trueif the box should be filled,falseotherwise
Returns: self for chaining.
fillAlpha
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
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.
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 boxalpha: the alpha value for the box's fill color
Returns: self for chaining.
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 colorg: the green component of the fill colorb: the blue component of the fill color
Returns: self for chaining.
Packs RGB without clamping or masking and stores alpha separately from the outline.
Parameters:
r: the red component of the fill colorg: the green component of the fill colorb: the blue component of the fill colora: the alpha component of the fill color
Returns: self for chaining.
forBlock
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 blocky: the y coordinate of the blockz: the z coordinate of the block
Returns: self for chaining.
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
Returns the separately stored outline alpha; it is independent of the fill alpha.
Returns: the alpha value of the box's color.
getColor
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
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
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
getPos2
isCulled
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
Returns whether the builder enables drawing the box's inside.
Returns:
true if the box should be filled, false otherwise.pos
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 boxy1: the y coordinate of the first position of the boxz1: the z coordinate of the first position of the boxx2: the x coordinate of the second position of the boxy2: the y coordinate of the second position of the boxz2: the z coordinate of the second position of the box
Returns: self for chaining.
Sets both corners from the block positions' integer coordinates, converting each helper to a position object.
Parameters:
pos1: the first position of the boxpos2: the second position of the box
Returns: self for chaining.
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 boxpos2: the second position of the box
Returns: self for chaining.
pos1
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.
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.
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 boxy1: the y coordinate of the first position of the boxz1: the z coordinate of the first position of the box
Returns: self for chaining.
pos2
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.
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.
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 boxy2: the y coordinate of the second position of the boxz2: the z coordinate of the second position of the box
Returns: self for chaining.