Skip to content

Commit

Permalink
ControlEntityRenderer tweaks
Browse files Browse the repository at this point in the history
-Made colour change less frequent for easier viewing experience
-Fixed misdocumented variables
  • Loading branch information
50ap5ud5 committed Dec 27, 2023
1 parent 6f488fc commit fa7566e
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,34 @@ public void render(ControlEntity entity, float f, float g, PoseStack poseStack,
}

@Override
protected void renderNameTag(ControlEntity entity, Component component, PoseStack poseStack, MultiBufferSource multiBufferSource, int textRenderingLayer) {
protected void renderNameTag(ControlEntity entity, Component component, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLightCoords) {
MutableComponent textComponent = Component.literal(component.getString());
textComponent.withStyle(style -> style
.applyFormats(ChatFormatting.BOLD, (entity.level().random.nextInt(50) == 0) ? ChatFormatting.GOLD : ChatFormatting.YELLOW)
.applyFormats(ChatFormatting.BOLD, (entity.level().getGameTime() % 60 == 0) ? ChatFormatting.GOLD : ChatFormatting.YELLOW)
);

double distanceSquared = this.entityRenderDispatcher.distanceToSqr(entity);
if (!(distanceSquared > 4096.0)) {
boolean isSolid = !entity.isDiscrete();
float boundingBoxHeight = entity.getBbHeight() + 0.5F;
float boundingBoxHeight = entity.getNameTagOffsetY();
int verticalTextOffset = 35;
poseStack.pushPose();
poseStack.translate(0.0, boundingBoxHeight, 0.0);

poseStack.mulPose(this.entityRenderDispatcher.cameraOrientation());


float scale = 0.010F;
poseStack.scale(-scale, -scale, scale);

Matrix4f textMatrix = poseStack.last().pose();
float textBackgroundOpacity = Minecraft.getInstance().options.getBackgroundOpacity(0.75F);
float textBackgroundOpacity = Minecraft.getInstance().options.getBackgroundOpacity(0.5F);

int textColor = (int) (textBackgroundOpacity * 255.0F) << 24;
Font font = this.getFont();
float textHorizontalPosition = (float) (-font.width(component) / 2);

font.drawInBatch(textComponent, textHorizontalPosition, (float) verticalTextOffset, 553648127, false, textMatrix, multiBufferSource, Font.DisplayMode.NORMAL, textColor, textRenderingLayer);
font.drawInBatch(textComponent, textHorizontalPosition, (float) verticalTextOffset, 553648127, false, textMatrix, multiBufferSource, Font.DisplayMode.SEE_THROUGH, textColor, packedLightCoords);
if (isSolid) {
font.drawInBatch(textComponent, textHorizontalPosition, (float) verticalTextOffset, -1, false, textMatrix, multiBufferSource, Font.DisplayMode.SEE_THROUGH, 0, textRenderingLayer);
font.drawInBatch(textComponent, textHorizontalPosition, (float) verticalTextOffset, -1, false, textMatrix, multiBufferSource, Font.DisplayMode.NORMAL, 0, packedLightCoords);
}

poseStack.popPose();
Expand Down

0 comments on commit fa7566e

Please sign in to comment.