Surface.Builder
com.jsmacrosce.jsmacros.client.api.classes.render.components3d.Surface.Builder
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.
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
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 bybuildAndAdd(), ornullfor detached builds
Methods
bindToEntity
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
boundOffset
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
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 aty: the y offset from the entity's position to render the surface atz: the z offset from the entity's position to render the surface at
build
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();buildAndAdd
cull
false, which draws it over the world.Parameters:
cull: whether to enable culling or not
doesRotateToPlayer
false; when enabled, configured rotations are replaced during rendering.true if camera-facing rotation is enabledfullBrightLight
getBoundEntity
null if none is setgetBoundOffset
getHeight
10; this is distinct from a built surface's height in pixels.getMinSubdivisions
1. Values below 1 are reported unchanged here, though the built surface clamps them.getPos
0, 0, 0. If set with pos(Pos3D), it is the same object; edits affect future builds only.getWidth
10; this is distinct from a built surface's width in pixels.getXRotation
0 and is independent of built surfaces.getYRotation
0.getZIndexScale
0.001.getZRotation
0.height
10 blocks.Parameters:
height: the height of the surface
isCulled
false.true if depth testing is enabledisRotatingCenter
true.true if this surface should be rotated around its center,light
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)
minSubdivisions
1; values below 1 are retained by the builder but clamped to 1 on the built surface.Parameters:
minSubdivisions: the minimum number of subdivisions
pos
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
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
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 surfacey: the y position of the surfacez: the z position of the surface
renderBack
true.Parameters:
renderBack: whether the back of the surface should be rendered or not
rotateCenter
true for this builder.Parameters:
rotateCenter: whether to rotate around the center of the surface
rotateToPlayer
false.Parameters:
rotateToPlayer: whether to rotate the surface to face the player or not
rotation
Parameters:
xRot: the x rotation of the surfaceyRot: the y rotation of the surfacezRot: the z rotation of the surface
shouldRenderBack
true.true if the back should be renderedsize
Parameters:
width: the width of the surfaceheight: the height of the surface
width
10 blocks.Parameters:
width: the width of the surface
worldLight
xRotation
Parameters:
xRot: the x rotation of the surface
yRotation
Parameters:
yRot: the y rotation of the surface
zIndex
0.001; it does not position the surface itself.Parameters:
zIndexScale: the scale of the z-index
zRotation
Parameters:
zRot: the z rotation of the surface