use of net.minecraft.client.font.TextRenderer in project BlockMeter by ModProg.
the class ColorButton method render.
@Override
public void render(MatrixStack stack, final int int_1, final int int_2, final float float_1) {
super.render(stack, int_1, int_2, float_1);
RenderSystem.disableTexture();
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bufferBuilder = tessellator.getBuffer();
RenderSystem.setShader(GameRenderer::getPositionColorShader);
int r = this.color.getRed();
int g = this.color.getGreen();
int b = this.color.getBlue();
int a = texture ? 102 : 255;
bufferBuilder.begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
bufferBuilder.vertex((double) this.x - (texture ? 1 : 0), (double) this.y - (texture ? 1 : 0), 0.0).color(r, g, b, a).next();
bufferBuilder.vertex((double) this.x - (texture ? 1 : 0), this.y + this.height + (texture ? 1 : 0), 0.0).color(r, g, b, a).next();
bufferBuilder.vertex(this.x + this.width + (texture ? 1 : 0), this.y + this.height + (texture ? 1 : 0), 0.0).color(r, g, b, a).next();
bufferBuilder.vertex(this.x + this.width + (texture ? 1 : 0), (double) this.y - (texture ? 1 : 0), 0.0).color(r, g, b, a).next();
tessellator.draw();
RenderSystem.enableTexture();
if (text != null) {
boolean dark = (0.299f * color.getRed() + 0.587f * color.getBlue() + 0.114f * color.getRed()) / 255f < 0.8f;
@SuppressWarnings("resource") final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
int text_width = textRenderer.getWidth(text);
if (dark || texture)
textRenderer.drawWithShadow(stack, text, x + width / 2 - text_width / 2, y + height / 2 - 4, 0xFFFFFF);
else {
// shadow
textRenderer.draw(stack, text, x + width / 2 - text_width / 2 + 1, y + height / 2 - 3, 0xAAAAAA);
textRenderer.draw(stack, text, x + width / 2 - text_width / 2, y + height / 2 - 4, 0);
}
}
}
use of net.minecraft.client.font.TextRenderer in project BlockMeter by ModProg.
the class ClientMeasureBox method drawText.
/**
* Draws a text with orientation and position
*
* @param stack
* @param x
* @param y
* @param z
* @param yaw
* @param pitch
* @param text
* @param playerPos
*/
private void drawText(final MatrixStack stack, final double x, final double y, final double z, final float yaw, final float pitch, final String text, final Vec3d playerPos) {
@SuppressWarnings("resource") final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
final LiteralText literalText = new LiteralText(text);
float size = 0.03f;
final int constDist = 10;
if (AutoConfig.getConfigHolder(ModConfig.class).getConfig().minimalLabelSize) {
final float dist = (float) Math.sqrt((x - playerPos.x) * (x - playerPos.x) + (y - playerPos.y) * (y - playerPos.y) + (z - playerPos.z) * (z - playerPos.z));
if (dist > constDist)
size = dist * size / constDist;
}
stack.push();
stack.translate(x, y + 0.15, z);
stack.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(180.0F - yaw));
stack.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(-pitch));
stack.scale(size, -size, 0.001f);
final int width = textRenderer.getWidth(literalText);
stack.translate((-width / 2), 0.0, 0.0);
final Matrix4f model = stack.peek().getPositionMatrix();
final BufferBuilder buffer = Tessellator.getInstance().getBuffer();
int textColor = color.getSignColor();
final ModConfig conf = BlockMeterClient.getConfigManager().getConfig();
if (conf.backgroundForLabels) {
final float[] colors = this.color.getColorComponents();
buffer.begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
buffer.vertex(model, -1, -1, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
buffer.vertex(model, -1, 8, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
buffer.vertex(model, width, 8, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
buffer.vertex(model, width, -1, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
Tessellator.getInstance().draw();
float[] components = color.getColorComponents();
float luminance = (0.299f * components[0] + 0.587f * components[1] + 0.114f * components[2]);
textColor = luminance < 0.4f ? DyeColor.WHITE.getSignColor() : DyeColor.BLACK.getSignColor();
}
final VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(buffer);
textRenderer.draw(literalText, 0.0f, 0.0f, textColor, // shadow
!conf.backgroundForLabels, // matrix
model, // draw buffer
immediate, // seeThrough
true, // backgroundColor => underlineColor,
0, // light
15728880);
immediate.draw();
stack.pop();
}
use of net.minecraft.client.font.TextRenderer in project meteor-client by MeteorDevelopment.
the class PlayerListHudMixin method renderLatencyIcon.
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/PlayerListHud;renderLatencyIcon(Lnet/minecraft/client/util/math/MatrixStack;IIILnet/minecraft/client/network/PlayerListEntry;)V"))
protected void renderLatencyIcon(PlayerListHud self, MatrixStack matrices, int width, int x, int y, PlayerListEntry entry) {
BetterTab betterTab = Modules.get().get(BetterTab.class);
if (betterTab.isActive() && betterTab.accurateLatency.get()) {
MinecraftClient mc = MinecraftClient.getInstance();
TextRenderer textRenderer = mc.textRenderer;
int latency = Utils.clamp(entry.getLatency(), 0, 9999);
int color = latency < 150 ? 0x00E970 : latency < 300 ? 0xE7D020 : 0xD74238;
String text = latency + "ms";
textRenderer.drawWithShadow(matrices, text, (float) x + width - textRenderer.getWidth(text), (float) y, color);
} else {
renderLatencyIcon(matrices, width, x, y, entry);
}
}
use of net.minecraft.client.font.TextRenderer in project tweakermore by Fallen-Breath.
the class ShulkerToolTipEnhancer method appendEnchantmentHints.
public static void appendEnchantmentHints(ItemStack itemStack, Text text) {
if (TweakerMoreConfigs.SHULKER_TOOLTIP_ENCHANTMENT_HINT.getBooleanValue()) {
List<Text> enchantmentTexts = Lists.newArrayList();
ListTag enchantmentTag = itemStack.getItem() instanceof EnchantedBookItem ? EnchantedBookItem.getEnchantmentTag(itemStack) : itemStack.getEnchantments();
ItemStack.appendEnchantments(enchantmentTexts, enchantmentTag);
int amount = enchantmentTexts.size();
if (amount > 0) {
TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
Text extraText = new LiteralText(" | ").formatted(Formatting.DARK_GRAY);
int idx;
for (idx = 0; idx < amount; idx++) {
if (idx > 0 && textRenderer.getStringWidth(extraText.getString() + enchantmentTexts.get(idx).getString()) > MAX_TEXT_LENGTH) {
break;
}
extraText.append(enchantmentTexts.get(idx));
if (idx < amount - 1) {
extraText.append(new LiteralText(", ").formatted(Formatting.GRAY));
}
}
if (idx < amount) {
extraText.append(new TranslatableText("tweakermore.config.shulkerTooltipEnchantmentHint.more", amount - idx).formatted(Formatting.GRAY));
}
text.append(extraText);
}
}
}
use of net.minecraft.client.font.TextRenderer in project KiwiClient by TangyKiwi.
the class PlayerListHudMixin method renderLatencyIcon.
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/PlayerListHud;renderLatencyIcon(Lnet/minecraft/client/util/math/MatrixStack;IIILnet/minecraft/client/network/PlayerListEntry;)V"))
protected void renderLatencyIcon(PlayerListHud self, MatrixStack matrices, int width, int x, int y, PlayerListEntry entry) {
BetterTab module = (BetterTab) KiwiClient.moduleManager.getModule(BetterTab.class);
if (module.isEnabled() && module.getSetting(1).asToggle().state) {
TextRenderer textRenderer = Utils.mc.textRenderer;
int latency = clamp(entry.getLatency(), 0, 9999);
int color = ColorUtil.getColorString(latency, 10, 20, 50, 75, 100, true);
String text = latency + "ms";
textRenderer.drawWithShadow(matrices, text, (float) x + width - textRenderer.getWidth(text), (float) y, color);
} else {
renderLatencyIcon(matrices, width, x, y, entry);
}
}
Aggregations