Search in sources :

Example 1 with TooltipComponent

use of net.minecraft.client.gui.tooltip.TooltipComponent 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 TooltipComponent

use of net.minecraft.client.gui.tooltip.TooltipComponent in project frame-fabric by moddingplayground.

the class TabWidget method renderTooltip.

@Override
public void renderTooltip(MatrixStack matrices, int mouseX, int mouseY) {
    MinecraftClient client = MinecraftClient.getInstance();
    if (client.currentScreen != null && !this.isSelected()) {
        Text message = this.getMessage();
        TooltipComponent tooltip = TooltipComponent.of(message.asOrderedText());
        int width = tooltip.getWidth(client.textRenderer);
        int height = tooltip.getHeight();
        int ox = this.isRightColumn() ? -this.width + 62 : -(width + this.width) + 20;
        int oz = -(height + this.height) + 16;
        client.currentScreen.renderTooltip(matrices, message, x + ox, y - oz);
    }
}
Also used : MinecraftClient(net.minecraft.client.MinecraftClient) Text(net.minecraft.text.Text) TooltipComponent(net.minecraft.client.gui.tooltip.TooltipComponent)

Example 3 with TooltipComponent

use of net.minecraft.client.gui.tooltip.TooltipComponent in project BleachHack by BleachDrinker420.

the class Peek method drawScreen.

@BleachSubscribe
public void drawScreen(EventRenderTooltip event) {
    if (!(event.getScreen() instanceof HandledScreen)) {
        return;
    }
    Slot slot = ((HandledScreen<?>) event.getScreen()).focusedSlot;
    if (slot == null)
        return;
    if (slot.x != slotX || slot.y != slotY) {
        pageCount = 0;
        pages = null;
        slotX = slot.x;
        slotY = slot.y;
    }
    event.getMatrix().push();
    event.getMatrix().translate(0, 0, 400);
    if (getSetting(0).asToggle().getState()) {
        List<TooltipComponent> components = drawShulkerToolTip(event.getMatrix(), slot, event.getMouseX(), event.getMouseY());
        if (components != null) {
            if (components.isEmpty()) {
                event.setCancelled(true);
            } else {
                event.setComponents(components);
            }
        }
    }
    if (getSetting(1).asToggle().getState())
        drawBookToolTip(event.getMatrix(), slot, event.getMouseX(), event.getMouseY());
    if (getSetting(2).asToggle().getState())
        drawMapToolTip(event.getMatrix(), slot, event.getMouseX(), event.getMouseY());
    event.getMatrix().pop();
}
Also used : HandledScreen(net.minecraft.client.gui.screen.ingame.HandledScreen) Slot(net.minecraft.screen.slot.Slot) TooltipComponent(net.minecraft.client.gui.tooltip.TooltipComponent) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Aggregations

TooltipComponent (net.minecraft.client.gui.tooltip.TooltipComponent)3 MinecraftClient (net.minecraft.client.MinecraftClient)2 Text (net.minecraft.text.Text)2 HandledScreen (net.minecraft.client.gui.screen.ingame.HandledScreen)1 Slot (net.minecraft.screen.slot.Slot)1 OrderedText (net.minecraft.text.OrderedText)1 Matrix4f (net.minecraft.util.math.Matrix4f)1 BleachSubscribe (org.bleachhack.eventbus.BleachSubscribe)1