Search in sources :

Example 11 with TextRenderer

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);
        }
    }
}
Also used : Tessellator(net.minecraft.client.render.Tessellator) BufferBuilder(net.minecraft.client.render.BufferBuilder) GameRenderer(net.minecraft.client.render.GameRenderer) TextRenderer(net.minecraft.client.font.TextRenderer)

Example 12 with TextRenderer

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();
}
Also used : Matrix4f(net.minecraft.util.math.Matrix4f) BufferBuilder(net.minecraft.client.render.BufferBuilder) TextRenderer(net.minecraft.client.font.TextRenderer) LiteralText(net.minecraft.text.LiteralText) ModConfig(win.baruna.blockmeter.ModConfig) VertexConsumerProvider(net.minecraft.client.render.VertexConsumerProvider)

Example 13 with TextRenderer

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);
    }
}
Also used : BetterTab(meteordevelopment.meteorclient.systems.modules.misc.BetterTab) MinecraftClient(net.minecraft.client.MinecraftClient) TextRenderer(net.minecraft.client.font.TextRenderer) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 14 with TextRenderer

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);
        }
    }
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) EnchantedBookItem(net.minecraft.item.EnchantedBookItem) LiteralText(net.minecraft.text.LiteralText) TranslatableText(net.minecraft.text.TranslatableText) Text(net.minecraft.text.Text) ListTag(net.minecraft.nbt.ListTag) TextRenderer(net.minecraft.client.font.TextRenderer) LiteralText(net.minecraft.text.LiteralText)

Example 15 with TextRenderer

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);
    }
}
Also used : BetterTab(com.tangykiwi.kiwiclient.modules.client.BetterTab) TextRenderer(net.minecraft.client.font.TextRenderer) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

TextRenderer (net.minecraft.client.font.TextRenderer)45 Point (de.johni0702.minecraft.gui.utils.lwjgl.Point)9 ReadablePoint (de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)9 MinecraftClient (net.minecraft.client.MinecraftClient)7 LiteralText (net.minecraft.text.LiteralText)7 Dimension (de.johni0702.minecraft.gui.utils.lwjgl.Dimension)6 ReadableDimension (de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension)6 TranslatableText (net.minecraft.text.TranslatableText)5 ReadableColor (de.johni0702.minecraft.gui.utils.lwjgl.ReadableColor)3 GameRenderer (net.minecraft.client.render.GameRenderer)3 MatrixStack (net.minecraft.client.util.math.MatrixStack)3 Text (net.minecraft.text.Text)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Environment (net.fabricmc.api.Environment)2 InGameHud (net.minecraft.client.gui.hud.InGameHud)2 Screen (net.minecraft.client.gui.screen.Screen)2 BufferBuilder (net.minecraft.client.render.BufferBuilder)2 I18n (net.minecraft.client.resource.language.I18n)2 Sprite (net.minecraft.client.texture.Sprite)2