Skip to content

Surface.Builder ​

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

Since1.8.4

Builder for configuring and creating a Surface.

A chain of setters, then build() for a surface that is not put anywhere or buildAndAdd() for one added to the 3D overlay it was made from. A surface on its own draws nothing either way; the overlay has to be registered before it is drawn.

The defaults are a surface ten blocks on a side at the origin, rotated about its middle, with its back drawn, not depth tested, drawn over everything, lit at full brightness and not following anybody. Ten blocks is a large default for a panel whose elements are measured in pixels, so the size is normally set explicitly.

js
const draw = Hud.createDraw3D();  
const surface = draw.surfaceBuilder()
  .pos(0.5, 64, 0.5)
  .size(1, 1)
  .minSubdivisions(200)
  .rotateToPlayer(true)
  .buildAndAdd();  
surface.addText("a label", 10, 10, Color.rgb(0xFF, 0xFF, 0xFF), true);  
draw.register();

Nested type declared in Surface.

Constructors ​

new Surface.Builder ​

new Surface.Builder(Draw3D parent)#
Creates a builder with origin position, zero rotations, a 10 by 10 block size, and one subdivision across the smaller side. The parent is retained for buildAndAdd(); a null parent allows detached build() calls, but buildAndAdd() then throws NullPointerException when it attempts to add the surface.

Parameters:

  • parent: overlay used by buildAndAdd(), or null for detached builds

Methods ​

bindToEntity ​

bindToEntity(EntityHelper<?> boundEntity): Surface.BuilderSince1.8.4#
Sets the entity to follow. A live entity's interpolated position plus the configured offset determines the render position; otherwise the configured builder position is used. Passing null leaves the surface unbound.
const player = Player.getPlayer();
if (player !== null) {
  const draw = Hud.createDraw3D();
  draw.surfaceBuilder()
     .bindToEntity(player)
     .boundOffset(0, 1.8, 0)
     .size(0.5, 0.5)
     .rotateToPlayer(true)
     .buildAndAdd();
  draw.register();
}

Parameters:

  • boundEntity: the entity to bind the surface to
Returns: self for chaining.

boundOffset ​

boundOffset(Pos3D entityOffset): Surface.BuilderSince1.8.4#
Sets the entity-following offset in blocks, retained by reference and shared with surfaces built by this builder. It has no effect while unbound.
const player = Player.getPlayer();
if (player !== null) {
  const draw = Hud.createDraw3D();
  const lift = PositionCommon.createPos(0, 1.8, 0);
  draw.surfaceBuilder().bindToEntity(player).boundOffset(lift).size(0.5, 0.5).buildAndAdd();
  // moving the offset after the fact moves the surface with it
  lift.y = 2.4;
  draw.register();
}

Parameters:

  • entityOffset: the offset from the entity's position to render the surface at
Returns: self for chaining.
boundOffset(double x, double y, double z): Surface.BuilderSince1.8.4#
Sets the entity-following offset in blocks, creating a new position object rather than sharing one supplied by the caller.
const player = Player.getPlayer();
if (player !== null) {
  const draw = Hud.createDraw3D();
  draw.surfaceBuilder().bindToEntity(player).boundOffset(0, 1.8, 0).size(0.5, 0.5).buildAndAdd();
  draw.register();
}

Parameters:

  • x: the x offset from the entity's position to render the surface at
  • y: the y offset from the entity's position to render the surface at
  • z: the z offset from the entity's position to render the surface at
Returns: self for chaining.

build ​

build(): Surface#
Builds an unattached surface. Position, rotation, and size are copied; the surface shares the builder's current bound-offset object, so mutating that object affects both, but later replacing the builder's offset does not change the built surface. Other builder settings are copied. Add the result to a 3D overlay before it can draw.
const draw = Hud.createDraw3D();
const surface = draw.surfaceBuilder().pos(0, 64, 0).size(1, 1).build();
// built but not added, so it is not in the overlay yet
draw.addSurface(surface);
surface.addText("hello", 10, 10, Color.rgb(0xFF, 0xFF, 0xFF), true);
draw.register();
Returns: the build surface.

buildAndAdd ​

buildAndAdd(): SurfaceSince1.8.4#
Builds the surface and adds it to the originating overlay. It draws when that overlay is registered. Subdivision counts below 1 are clamped on the built surface, not on this builder.
Returns: the build surface.

cull ​

cull(boolean cull): Surface.BuilderSince1.8.4#
Enables depth testing, allowing terrain to obscure the surface. The default is false, which draws it over the world.

Parameters:

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

doesRotateToPlayer ​

doesRotateToPlayer(): booleanSince1.8.4#
Returns whether the builder enables camera-facing rotation. It defaults to false; when enabled, configured rotations are replaced during rendering.
Returns: true if camera-facing rotation is enabled

fullBrightLight ​

fullBrightLight(): Surface.BuilderSince2.1.0#
Renders all elements at full brightness, ignoring world lighting.
Returns: self for chaining.

getBoundEntity ​

getBoundEntity(): EntityHelper<?>Since1.8.4#
Returns the entity configured for the surface, if any.
Returns: the bound entity, or null if none is set

getBoundOffset ​

getBoundOffset(): Pos3DSince1.8.4#
Returns the builder's offset object, initially 0, 0, 0. Built surfaces share this object, so mutating it changes their bound offset.
Returns: the entity-following offset in blocks

getHeight ​

getHeight(): doubleSince1.8.4#
Returns the builder's physical height in blocks, initially 10; this is distinct from a built surface's height in pixels.
Returns: the height of the surface.

getMinSubdivisions ​

getMinSubdivisions(): intSince1.8.4#
Returns the builder's subdivision count, initially 1. Values below 1 are reported unchanged here, though the built surface clamps them.
Returns: the minimum number of subdivisions.

getPos ​

getPos(): Pos3DSince1.8.4#
Returns the builder's position object, initially 0, 0, 0. If set with pos(Pos3D), it is the same object; edits affect future builds only.
Returns: the builder's position

getWidth ​

getWidth(): doubleSince1.8.4#
Returns the builder's physical width in blocks, initially 10; this is distinct from a built surface's width in pixels.
Returns: the width of the surface.

getXRotation ​

getXRotation(): doubleSince1.8.4#
Returns this builder's x-axis rotation; it defaults to 0 and is independent of built surfaces.
Returns: the x rotation of the surface.

getYRotation ​

getYRotation(): doubleSince1.8.4#
Returns this builder's y-axis rotation; it defaults to 0.
Returns: the y rotation of the surface.

getZIndexScale ​

getZIndexScale(): doubleSince1.8.4#
Returns this builder's z-index scale, initially 0.001.
Returns: the scale of the z-index.

getZRotation ​

getZRotation(): doubleSince1.8.4#
Returns this builder's z-axis rotation; it defaults to 0.
Returns: the z rotation of the surface.

height ​

height(double height): Surface.BuilderSince1.8.4#
Sets the panel's physical height in blocks, independent of its element coordinate height. The default is 10 blocks.

Parameters:

  • height: the height of the surface
Returns: self for chaining.

isCulled ​

isCulled(): booleanSince1.8.4#
Returns whether depth testing is enabled for surfaces built by this builder. The default is false.
Returns: true if depth testing is enabled

isRotatingCenter ​

isRotatingCenter(): booleanSince1.8.4#
Returns whether this builder uses the panel center as the rotation pivot; defaults to true.
Returns: true if this surface should be rotated around its center,

light ​

light(int blockLight, int skyLight): Surface.BuilderSince2.1.0#
Sets fixed block and sky light levels for elements on the built surface.

Parameters:

  • blockLight: block light level, 0-15 (e.g. 15 next to a torch)
  • skyLight: sky light level, 0-15 (e.g. 15 outdoors in daylight)
Returns: self for chaining.

minSubdivisions ​

minSubdivisions(int minSubdivisions): Surface.BuilderSince1.8.4#
Sets the number of surface pixels across the smaller side, which determines the element coordinate scale. Defaults to 1; values below 1 are retained by the builder but clamped to 1 on the built surface.

Parameters:

  • minSubdivisions: the minimum number of subdivisions
Returns: self for chaining.

pos ​

pos(Pos3D pos): Surface.BuilderSince1.8.4#
Sets the panel's top-left corner in world blocks. The builder retains pos by reference, but each built surface receives a coordinate copy.
const draw = Hud.createDraw3D();
const where = PositionCommon.createPos(0.5, 64, 0.5);
draw.surfaceBuilder().pos(where).size(1, 1).buildAndAdd();
// changing this position affects future builds, not the surface already built
where.y = 70;
draw.register();

Parameters:

  • pos: the position of the surface
Returns: self for chaining.
pos(BlockPosHelper pos): Surface.BuilderSince1.8.4#
Sets the panel's top-left corner to the block position's coordinates.
const player = Player.getPlayer();
if (player !== null) {
  const draw = Hud.createDraw3D();
  draw.surfaceBuilder().pos(player.getBlockPos()).size(1, 1).buildAndAdd();
  draw.register();
}

Parameters:

  • pos: the position of the surface
Returns: self for chaining.
pos(double x, double y, double z): Surface.BuilderSince1.8.4#
Sets the panel's top-left corner in world blocks. Each built surface receives its own copy of these coordinates.
const draw = Hud.createDraw3D();
draw.surfaceBuilder().pos(0.5, 64, 0.5).size(1, 1).buildAndAdd();
draw.register();

Parameters:

  • x: the x position of the surface
  • y: the y position of the surface
  • z: the z position of the surface
Returns: self for chaining.

renderBack ​

renderBack(boolean renderBack): Surface.BuilderSince1.8.4#
Sets whether the surface is drawn when the camera is on its back side. The default is true.

Parameters:

  • renderBack: whether the back of the surface should be rendered or not
Returns: self for chaining.

rotateCenter ​

rotateCenter(boolean rotateCenter): Surface.BuilderSince1.8.4#
Sets whether rotations, camera-facing orientation, and nested 2D overlays pivot around the center. Defaults to true for this builder.

Parameters:

  • rotateCenter: whether to rotate around the center of the surface
Returns: self for chaining.

rotateToPlayer ​

rotateToPlayer(boolean rotateToPlayer): Surface.BuilderSince1.8.4#
Enables camera-facing rotation, which replaces the configured rotations each frame. Defaults to false.

Parameters:

  • rotateToPlayer: whether to rotate the surface to face the player or not
Returns: self for chaining.

rotation ​

rotation(double xRot, double yRot, double zRot): Surface.BuilderSince1.8.4#
Sets all three rotations in degrees, in x, y, z argument order. They are applied in y, x, z order.

Parameters:

  • xRot: the x rotation of the surface
  • yRot: the y rotation of the surface
  • zRot: the z rotation of the surface
Returns: self for chaining.

shouldRenderBack ​

shouldRenderBack(): booleanSince1.8.4#
Returns whether this builder enables rendering from the back side. It defaults to true.
Returns: true if the back should be rendered

size ​

size(double width, double height): Surface.BuilderSince1.8.4#
Sets the panel's physical width and height in blocks. Element coordinate dimensions are determined by minSubdivisions(int).

Parameters:

  • width: the width of the surface
  • height: the height of the surface
Returns: self for chaining.

width ​

width(double width): Surface.BuilderSince1.8.4#
Sets the panel's physical width in blocks; this is independent of its element coordinate width. The default is 10 blocks.

Parameters:

  • width: the width of the surface
Returns: self for chaining.

worldLight ​

worldLight(): Surface.BuilderSince2.1.0#
Samples block and sky light each frame at the surface's render position. If no world is loaded, lighting is full bright; sky light accounts for sky darkening.
Returns: self for chaining.

xRotation ​

xRotation(double xRot): Surface.BuilderSince1.8.4#
Sets the x-axis rotation in degrees. Rotations are applied in y, x, then z order.

Parameters:

  • xRot: the x rotation of the surface
Returns: self for chaining.

yRotation ​

yRotation(double yRot): Surface.BuilderSince1.8.4#
Sets the y-axis rotation in degrees; it is applied before the x- and z-axis rotations.

Parameters:

  • yRot: the y rotation of the surface
Returns: self for chaining.

zIndex ​

zIndex(double zIndexScale): Surface.BuilderSince1.8.4#
Sets the depth offset per z-index step for elements on the surface, in blocks. The default is 0.001; it does not position the surface itself.

Parameters:

  • zIndexScale: the scale of the z-index
Returns: self for chaining.

zRotation ​

zRotation(double zRot): Surface.BuilderSince1.8.4#
Sets the z-axis rotation in degrees; it is applied after the y- and x-axis rotations.

Parameters:

  • zRot: the z rotation of the surface
Returns: self for chaining.