Search in sources :

Example 1 with OrderedText

use of net.minecraft.text.OrderedText in project MasaGadget by plusls.

the class InventoryOverlayRenderHandler method renderOrderedTooltip.

public void renderOrderedTooltip(MatrixStack matrices, ItemStack stack, int x, int y) {
    y = y + 8;
    MinecraftClient mc = MinecraftClient.getInstance();
    List<OrderedText> lines = Lists.transform(stack.getTooltip(mc.player, mc.options.advancedItemTooltips ? TooltipContext.Default.ADVANCED : TooltipContext.Default.NORMAL), Text::asOrderedText);
    List<TooltipComponent> components = lines.stream().map(TooltipComponent::of).collect(Collectors.toList());
    if (components.isEmpty())
        return;
    int k = 0;
    int l = (components.size() == 1) ? -2 : 0;
    for (TooltipComponent lv : components) {
        int m = lv.getWidth(mc.textRenderer);
        if (m > k)
            k = m;
        l += lv.getHeight();
    }
    int n = x + 12;
    int o = y - 12;
    int p = k;
    int q = l;
    if (n + k > GuiUtils.getScaledWindowWidth())
        n -= 28 + k;
    if (o + q + 6 > GuiUtils.getScaledWindowHeight())
        o = GuiUtils.getScaledWindowHeight() - q - 6;
    matrices.push();
    int r = -267386864;
    int s = 1347420415;
    int t = 1344798847;
    int u = 400;
    float f = mc.getItemRenderer().zOffset;
    mc.getItemRenderer().zOffset = 400.0F;
    Tessellator lv2 = Tessellator.getInstance();
    BufferBuilder lv3 = lv2.getBuffer();
    RenderSystem.setShader(GameRenderer::getPositionColorShader);
    lv3.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR);
    Matrix4f lv4 = matrices.peek().getPositionMatrix();
    fillGradient(lv4, lv3, n - 3, o - 4, n + p + 3, o - 3, 400, -267386864, -267386864);
    fillGradient(lv4, lv3, n - 3, o + q + 3, n + p + 3, o + q + 4, 400, -267386864, -267386864);
    fillGradient(lv4, lv3, n - 3, o - 3, n + p + 3, o + q + 3, 400, -267386864, -267386864);
    fillGradient(lv4, lv3, n - 4, o - 3, n - 3, o + q + 3, 400, -267386864, -267386864);
    fillGradient(lv4, lv3, n + p + 3, o - 3, n + p + 4, o + q + 3, 400, -267386864, -267386864);
    fillGradient(lv4, lv3, n - 3, o - 3 + 1, n - 3 + 1, o + q + 3 - 1, 400, 1347420415, 1344798847);
    fillGradient(lv4, lv3, n + p + 2, o - 3 + 1, n + p + 3, o + q + 3 - 1, 400, 1347420415, 1344798847);
    fillGradient(lv4, lv3, n - 3, o - 3, n + p + 3, o - 3 + 1, 400, 1347420415, 1347420415);
    fillGradient(lv4, lv3, n - 3, o + q + 2, n + p + 3, o + q + 3, 400, 1344798847, 1344798847);
    RenderSystem.enableDepthTest();
    RenderSystem.disableTexture();
    RenderSystem.enableBlend();
    RenderSystem.defaultBlendFunc();
    lv3.end();
    BufferRenderer.draw(lv3);
    RenderSystem.disableBlend();
    RenderSystem.enableTexture();
    VertexConsumerProvider.Immediate lv5 = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
    matrices.translate(0.0D, 0.0D, 400.0D);
    int v = o;
    for (int w = 0; w < components.size(); w++) {
        TooltipComponent lv6 = components.get(w);
        lv6.drawText(mc.textRenderer, n, v, lv4, lv5);
        v += lv6.getHeight() + ((w == 0) ? 2 : 0);
    }
    lv5.draw();
    matrices.pop();
    v = o;
    for (int i = 0; i < components.size(); i++) {
        TooltipComponent lv7 = components.get(i);
        lv7.drawItems(mc.textRenderer, n, v, matrices, mc.getItemRenderer(), 400);
        v += lv7.getHeight() + ((i == 0) ? 2 : 0);
    }
    mc.getItemRenderer().zOffset = f;
}
Also used : OrderedText(net.minecraft.text.OrderedText) Text(net.minecraft.text.Text) Matrix4f(net.minecraft.util.math.Matrix4f) MinecraftClient(net.minecraft.client.MinecraftClient) OrderedText(net.minecraft.text.OrderedText) TooltipComponent(net.minecraft.client.gui.tooltip.TooltipComponent)

Example 2 with OrderedText

use of net.minecraft.text.OrderedText in project MiniMap by pl3xgaming.

the class Tab method render.

@Override
public void render(MatrixStack matrixStack, float mouseX, float mouseY, float delta) {
    super.render(matrixStack, mouseX, mouseY, delta);
    icon().tint(matrixStack, iconX(), iconY(), iconSize(), color());
    if (width() > Sidebar.DEFAULT_WIDTH) {
        if (width() < Sidebar.HOVER_WIDTH) {
            // only trim text if sidebar is between open and
            // closed states since this is sort of expensive
            StringVisitable str = Font.RALEWAY.trimToWidth(text(), (int) (width() - textX()));
            for (OrderedText orderedText : Font.RALEWAY.wrapLines(str, Integer.MAX_VALUE)) {
                Font.RALEWAY.draw(matrixStack, orderedText, textX(), textY(), color());
            }
        } else {
            Font.RALEWAY.draw(matrixStack, text(), textX(), textY(), color());
        }
    }
    if (hovered()) {
        Mouse.INSTANCE.cursor(Cursor.HAND_POINTER);
    }
}
Also used : StringVisitable(net.minecraft.text.StringVisitable) OrderedText(net.minecraft.text.OrderedText)

Example 3 with OrderedText

use of net.minecraft.text.OrderedText in project Blockify by clownless.

the class BlockifyHUD method draw.

public static void draw(MatrixStack matrixStack) {
    matrixStack.push();
    if (hudInfo[1] == null || isHidden) {
        return;
    }
    double percentProgress = (double) progressMS / (double) durationMS;
    if (percentProgress < 0) {
        percentProgress = 0;
    }
    BlockifyHUD.matrixStack = matrixStack;
    matrixStack.translate((BlockifyConfig.anchor == BlockifyConfig.Anchor.TOP_LEFT || BlockifyConfig.anchor == BlockifyConfig.Anchor.BOTTOM_LEFT) ? BlockifyConfig.posX : scaledWidth - 185 - BlockifyConfig.posX, (BlockifyConfig.anchor == BlockifyConfig.Anchor.TOP_LEFT || BlockifyConfig.anchor == BlockifyConfig.Anchor.TOP_RIGHT) ? BlockifyConfig.posY : scaledHeight - 55 - BlockifyConfig.posY, 0);
    matrixStack.scale((float) BlockifyConfig.scale, (float) BlockifyConfig.scale, 1);
    scaledWidth = client.getWindow().getScaledWidth();
    scaledHeight = client.getWindow().getScaledHeight();
    // background
    drawRectangle(0, 0, 185, 55, new Color(MidnightColorUtil.hex2Rgb(BlockifyConfig.backgroundColor).getRed(), MidnightColorUtil.hex2Rgb(BlockifyConfig.backgroundColor).getGreen(), MidnightColorUtil.hex2Rgb(BlockifyConfig.backgroundColor).getBlue(), BlockifyConfig.backgroundTransparency));
    // progressbar
    drawRectangle(60, 48, 180, 50, MidnightColorUtil.hex2Rgb(BlockifyConfig.barColor).darker().darker());
    // progressbar
    drawRectangle(60, 48, (float) (60 + (120 * percentProgress)), 50, MidnightColorUtil.hex2Rgb(BlockifyConfig.barColor));
    if (hudInfo[4] != null && (!prevImage.equals(hudInfo[4]) && !hudInfo[4].equals(""))) {
        LOGGER.info("Drawing new album cover.");
        albumImage.setImage(hudInfo[4]);
        prevImage = hudInfo[4];
    }
    drawRectangle(5, 5, 50, 50, new Color(0, 0, 0, 150));
    if (hudInfo[4] != null) {
        RenderUtil.drawTexture(matrixStack, albumImage, 5, 5, .15F);
    }
    List<OrderedText> nameWrap = fontRenderer.wrapLines(StringVisitable.plain(hudInfo[0]), 125);
    int yOffset = 0;
    if (nameWrap.size() > 1) {
        fontRenderer.drawWithShadow(matrixStack, nameWrap.get(0), 60, 5, MidnightColorUtil.hex2Rgb(BlockifyConfig.titleColor).getRGB());
        fontRenderer.drawWithShadow(matrixStack, nameWrap.get(1), 60, 18, MidnightColorUtil.hex2Rgb(BlockifyConfig.titleColor).getRGB());
        yOffset = 15;
    } else {
        fontRenderer.drawWithShadow(matrixStack, nameWrap.get(0), 60, 5, MidnightColorUtil.hex2Rgb(BlockifyConfig.titleColor).getRGB());
        yOffset = 0;
    }
    matrixStack.scale(.5F, .5F, .5F);
    List<OrderedText> artistWrap = fontRenderer.wrapLines(StringVisitable.plain(hudInfo[1]), 140);
    int artistYOffset = 0;
    if (artistWrap.size() > 1) {
        fontRenderer.drawWithShadow(matrixStack, artistWrap.get(0), 120, 45 + yOffset, MidnightColorUtil.hex2Rgb(BlockifyConfig.artistColor).getRGB());
        fontRenderer.drawWithShadow(matrixStack, artistWrap.get(1), 120, 58 + yOffset, MidnightColorUtil.hex2Rgb(BlockifyConfig.artistColor).getRGB());
        artistYOffset = 15;
    } else {
        fontRenderer.drawWithShadow(matrixStack, artistWrap.get(0), 120, 45 + yOffset, MidnightColorUtil.hex2Rgb(BlockifyConfig.artistColor).getRGB());
        artistYOffset = 0;
    }
    String progressText = (progressMS / (1000 * 60)) + ":" + String.format("%02d", (progressMS / 1000 % 60));
    String durationText = (durationMS / (1000 * 60)) + ":" + String.format("%02d", (durationMS / 1000 % 60));
    fontRenderer.drawWithShadow(matrixStack, progressText, 120, 85, MidnightColorUtil.hex2Rgb(BlockifyConfig.timeColor).getRGB());
    fontRenderer.drawWithShadow(matrixStack, durationText, 360 - (fontRenderer.getWidth(durationText)), 85, MidnightColorUtil.hex2Rgb(BlockifyConfig.timeColor).getRGB());
    matrixStack.scale(2F, 2F, 2F);
    matrixStack.scale(1, 1, 1);
    matrixStack.pop();
}
Also used : Color(java.awt.Color) OrderedText(net.minecraft.text.OrderedText)

Example 4 with OrderedText

use of net.minecraft.text.OrderedText in project meteor-client by MeteorDevelopment.

the class BookTooltipComponent method drawItems.

@Override
public void drawItems(TextRenderer textRenderer, int x, int y, MatrixStack matrices, ItemRenderer itemRenderer, int z) {
    // Background
    RenderSystem.setShader(GameRenderer::getPositionTexShader);
    RenderSystem.setShaderTexture(0, TEXTURE_BOOK_BACKGROUND);
    DrawableHelper.drawTexture(matrices, x, y, z, 12, 0, 112, 134, 179, 179);
    // Content
    matrices.push();
    matrices.translate(x + 16, y + 12, z + 1);
    matrices.scale(0.7f, 0.7f, 1f);
    int offset = 0;
    for (OrderedText line : textRenderer.wrapLines(page, 112)) {
        textRenderer.draw(matrices, line, 0, offset, 0x000000);
        offset += 8;
    }
    matrices.pop();
}
Also used : GameRenderer(net.minecraft.client.render.GameRenderer) OrderedText(net.minecraft.text.OrderedText)

Example 5 with OrderedText

use of net.minecraft.text.OrderedText in project meteor-client by MeteorDevelopment.

the class ChatHudMixin method onRender.

@Inject(method = "render", at = @At("TAIL"))
private void onRender(MatrixStack matrices, int tickDelta, CallbackInfo ci) {
    if (!Modules.get().get(BetterChat.class).displayPlayerHeads())
        return;
    if (mc.options.chatVisibility == ChatVisibility.HIDDEN)
        return;
    int maxLineCount = mc.inGameHud.getChatHud().getVisibleLineCount();
    double d = mc.options.chatOpacity * 0.8999999761581421D + 0.10000000149011612D;
    double g = 9.0D * (mc.options.chatLineSpacing + 1.0D);
    double h = -8.0D * (mc.options.chatLineSpacing + 1.0D) + 4.0D * mc.options.chatLineSpacing + 8.0D;
    matrices.push();
    matrices.translate(2, -0.1f, 10);
    RenderSystem.enableBlend();
    for (int m = 0; m + this.scrolledLines < this.visibleMessages.size() && m < maxLineCount; ++m) {
        ChatHudLine<OrderedText> chatHudLine = this.visibleMessages.get(m + this.scrolledLines);
        if (chatHudLine != null) {
            int x = tickDelta - chatHudLine.getCreationTick();
            if (x < 200 || isChatFocused()) {
                double o = isChatFocused() ? 1.0D : getMessageOpacityMultiplier(x);
                if (o * d > 0.01D) {
                    double s = ((double) (-m) * g);
                    StringCharacterVisitor visitor = new StringCharacterVisitor();
                    chatHudLine.getText().accept(visitor);
                    drawIcon(matrices, visitor.result.toString(), (int) (s + h), (float) (o * d));
                }
            }
        }
    }
    RenderSystem.disableBlend();
    matrices.pop();
}
Also used : StringCharacterVisitor(meteordevelopment.meteorclient.utils.misc.text.StringCharacterVisitor) OrderedText(net.minecraft.text.OrderedText) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

OrderedText (net.minecraft.text.OrderedText)13 Text (net.minecraft.text.Text)3 TranslatableText (net.minecraft.text.TranslatableText)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 ArrayList (java.util.ArrayList)2 GameRenderer (net.minecraft.client.render.GameRenderer)2 Style (net.minecraft.text.Style)2 CommandNode (com.mojang.brigadier.tree.CommandNode)1 LiteralCommandNode (com.mojang.brigadier.tree.LiteralCommandNode)1 Color (java.awt.Color)1 Map (java.util.Map)1 OptionImpact (me.jellysquid.mods.sodium.client.gui.options.OptionImpact)1 Dim2i (me.jellysquid.mods.sodium.client.util.Dim2i)1 StringCharacterVisitor (meteordevelopment.meteorclient.utils.misc.text.StringCharacterVisitor)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 ChatHud (net.minecraft.client.gui.hud.ChatHud)1 ChatHudLine (net.minecraft.client.gui.hud.ChatHudLine)1 TooltipComponent (net.minecraft.client.gui.tooltip.TooltipComponent)1 CommandSource (net.minecraft.command.CommandSource)1 CharacterVisitor (net.minecraft.text.CharacterVisitor)1