Commit e3433d4e by Jonathan Thomas

Draw entity custom name above chat bubble / icons. Also, modified the chat…

Draw entity custom name above chat bubble / icons. Also, modified the chat bubble graphic to remove "X" icon.
parent dadd2aa8
Pipeline #11869 passed with stage
in 21 seconds
...@@ -135,6 +135,44 @@ public class ClientInit implements ClientModInitializer { ...@@ -135,6 +135,44 @@ public class ClientInit implements ClientModInitializer {
RenderSystem.disableDepthTest(); RenderSystem.disableDepthTest();
} }
private void drawMessageText(Matrix4f matrix, List<String> lines, int starting_line, int ending_line,
VertexConsumerProvider immediate, float lineSpacing, int fullBright, float yOffset) {
TextRenderer fontRenderer = MinecraftClient.getInstance().textRenderer;
int currentLineIndex = 0; // We'll use this to track which line we're on
for (String lineText : lines) {
// Only draw lines that are within the specified range
if (currentLineIndex >= starting_line && currentLineIndex < ending_line) {
fontRenderer.draw(lineText, -fontRenderer.getWidth(lineText) / 2f, yOffset, 0xffffff,
false, matrix, immediate, TextLayerType.NORMAL, 0, fullBright);
yOffset += fontRenderer.fontHeight + lineSpacing;
}
currentLineIndex++;
if (currentLineIndex > ending_line) {
break;
}
}
}
private void drawEndOfMessageText(Matrix4f matrix, VertexConsumerProvider immediate,
int fullBright, float yOffset) {
TextRenderer fontRenderer = MinecraftClient.getInstance().textRenderer;
String lineText = "<end of message>";
fontRenderer.draw(lineText, -fontRenderer.getWidth(lineText) / 2f, yOffset + 10F, 0xffffff,
false, matrix, immediate, TextLayerType.NORMAL, 0, fullBright);
}
private void drawEntityName(Entity entity, Matrix4f matrix, VertexConsumerProvider immediate,
int fullBright, float xOffset, float yOffset) {
if (entity.getCustomName() != null) {
TextRenderer fontRenderer = MinecraftClient.getInstance().textRenderer;
String lineText = entity.getCustomName().getString();
fontRenderer.draw(lineText, xOffset, yOffset, 0xffffff,
false, matrix, immediate, TextLayerType.NORMAL, 0, fullBright);
}
}
private void drawTextAboveEntities(WorldRenderContext context, float partialTicks) { private void drawTextAboveEntities(WorldRenderContext context, float partialTicks) {
Camera camera = context.camera(); Camera camera = context.camera();
Entity cameraEntity = camera.getFocusedEntity(); Entity cameraEntity = camera.getFocusedEntity();
...@@ -230,7 +268,8 @@ public class ClientInit implements ClientModInitializer { ...@@ -230,7 +268,8 @@ public class ClientInit implements ClientModInitializer {
float lineSpacing = 1F; float lineSpacing = 1F;
float textHeaderHeight = 40F; float textHeaderHeight = 40F;
float textFooterHeight = 5F; float textFooterHeight = 5F;
int fullBright = 0xF000F0;
Matrix4f matrix = matrices.peek().getPositionMatrix();
// Calculate size of text scaled to world // Calculate size of text scaled to world
float scaledTextHeight = linesDisplayed * (fontRenderer.fontHeight + lineSpacing); float scaledTextHeight = linesDisplayed * (fontRenderer.fontHeight + lineSpacing);
...@@ -243,6 +282,9 @@ public class ClientInit implements ClientModInitializer { ...@@ -243,6 +282,9 @@ public class ClientInit implements ClientModInitializer {
// Translate above the entity // Translate above the entity
matrices.translate(0F, -scaledTextHeight + -textHeaderHeight + -textFooterHeight, 0F); matrices.translate(0F, -scaledTextHeight + -textHeaderHeight + -textFooterHeight, 0F);
// Draw Entity (Custom Name)
drawEntityName(entity, matrix, immediate, fullBright, -25F, 22F + DISPLAY_PADDING);
// Check if conversation has started // Check if conversation has started
if (chatData.status == ChatDataManager.ChatStatus.NONE) { if (chatData.status == ChatDataManager.ChatStatus.NONE) {
// Draw 'start chat' button // Draw 'start chat' button
...@@ -260,30 +302,11 @@ public class ClientInit implements ClientModInitializer { ...@@ -260,30 +302,11 @@ public class ClientInit implements ClientModInitializer {
drawEntityIcon(matrices, entity, -59, 7, 32, 32); drawEntityIcon(matrices, entity, -59, 7, 32, 32);
// Render each line of the text // Render each line of the text
int fullBright = 0xF000F0; drawMessageText(matrix, lines, starting_line, ending_line, immediate, lineSpacing, fullBright, 40.0F + DISPLAY_PADDING);
Matrix4f matrix = matrices.peek().getPositionMatrix();
float yOffset = 40.0F + DISPLAY_PADDING;
int currentLineIndex = 0; // We'll use this to track which line we're on
for (String lineText : lines) {
// Only draw lines that are within the specified range
if (currentLineIndex >= starting_line && currentLineIndex < ending_line) {
fontRenderer.draw(lineText, -fontRenderer.getWidth(lineText) / 2f, yOffset, 0xffffff,
false, matrix, immediate, TextLayerType.NORMAL, 0, fullBright);
yOffset += fontRenderer.fontHeight + lineSpacing;
}
currentLineIndex++;
if (currentLineIndex > ending_line) {
break;
}
}
// Add end of message
if (starting_line > 0 && starting_line == ending_line) { if (starting_line > 0 && starting_line == ending_line) {
String lineText = "<end of message>"; // Add <End Of Message> text
fontRenderer.draw(lineText, -fontRenderer.getWidth(lineText) / 2f, yOffset + 10F, 0xffffff, drawEndOfMessageText(matrix, immediate, fullBright, 40.0F + DISPLAY_PADDING);
false, matrix, immediate, TextLayerType.NORMAL, 0, fullBright);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment