Search in sources :

Example 1 with Tooltip

use of me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.Tooltip in project BedrockIfy by juancarloscp52.

the class HeldItemTooltips method getTooltipsFromShulkerBox.

/**
 * Gets a tooltip list from the given shulkerBox compound tag.
 *
 * @param compoundTag compoundTag with item information.
 * @return Tooltip list.
 */
private List<Tooltip> getTooltipsFromShulkerBox(CompoundTag compoundTag) {
    ArrayList<Tooltip> shulkerTooltips = new ArrayList<Tooltip>();
    DefaultedList<ItemStack> items = DefaultedList.ofSize(27, ItemStack.EMPTY);
    Inventories.fromTag(compoundTag, items);
    for (ItemStack item : items) {
        if (!item.isEmpty())
            shulkerTooltips.add(new ShulkerBoxTooltip(item));
    }
    return shulkerTooltips;
}
Also used : PotionTooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.PotionTooltip) EnchantmentTooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.EnchantmentTooltip) Tooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.Tooltip) ShulkerBoxTooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.ShulkerBoxTooltip) ArrayList(java.util.ArrayList) ShulkerBoxTooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.ShulkerBoxTooltip) ItemStack(net.minecraft.item.ItemStack)

Example 2 with Tooltip

use of me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.Tooltip in project BedrockIfy by juancarloscp52.

the class HeldItemTooltips method getMaxTooltipLength.

private int getMaxTooltipLength(List<Tooltip> tooltips, TextRenderer textRenderer, ItemStack itemStack) {
    int count = 0;
    int maxLength = textRenderer.getWidth(itemStack.getName());
    for (Tooltip elem : tooltips) {
        int tipLength = textRenderer.getWidth(elem.getTooltipText());
        if (count > 3)
            tipLength = textRenderer.getWidth(new TranslatableText("container.shulkerBox.more", tooltips.size() - 4));
        if (maxLength < tipLength)
            maxLength = tipLength;
        if (count > 3)
            break;
        count++;
    }
    return maxLength;
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) PotionTooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.PotionTooltip) EnchantmentTooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.EnchantmentTooltip) Tooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.Tooltip) ShulkerBoxTooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.ShulkerBoxTooltip)

Example 3 with Tooltip

use of me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.Tooltip in project BedrockIfy by juancarloscp52.

the class ItemTooltipsMixin method interceptItemStack.

/**
 * Show the item tooltip when changing from a item to another of the same type and name IFF different tooltips.
 */
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;isEmpty()Z", ordinal = 1))
private boolean interceptItemStack(ItemStack itemStack) {
    ItemStack nextItem = this.client.player.inventory.getMainHandStack();
    HeldItemTooltips heldItemTooltips = BedrockifyClient.getInstance().heldItemTooltips;
    if (itemStack.getItem() == this.currentStack.getItem() && !heldItemTooltips.equals(currentStack, nextItem)) {
        this.heldItemTooltipFade = 41;
        return true;
    }
    return currentStack.isEmpty();
}
Also used : ItemStack(net.minecraft.item.ItemStack) HeldItemTooltips(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.HeldItemTooltips) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 4 with Tooltip

use of me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.Tooltip in project BedrockIfy by juancarloscp52.

the class HeldItemTooltips method drawItemWithCustomTooltips.

public int drawItemWithCustomTooltips(TextRenderer fontRenderer, MatrixStack matrices, Text text, float x, float y, int color, ItemStack currentStack) {
    int screenBorder = Bedrockify.getInstance().settings.getScreenSafeArea();
    // Get the current held item tooltips.
    List<Tooltip> tooltips = getTooltips(currentStack);
    int tooltipOffset = 0;
    BedrockifySettings settings = Bedrockify.getInstance().settings;
    // Draw item tooltips if the option is enabled.
    if (settings.getHeldItemTooltip() > 0) {
        if (tooltips != null) {
            // Compute the max tooltip offset (used for the item name).
            int count = 0;
            // Limit the maximum number of shown tooltips to 4.
            boolean showMoreTooltip = false;
            if (tooltips.size() > 4) {
                showMoreTooltip = true;
                tooltipOffset = 12 * 4;
                count++;
            } else
                tooltipOffset = tooltips.size() * 12;
            // Render background behind tooltip if enabled.
            if (settings.getHeldItemTooltip() == 2) {
                int maxLength = getMaxTooltipLength(tooltips, fontRenderer, currentStack);
                renderBackground(matrices, y, screenBorder, tooltipOffset, maxLength);
            }
            for (Tooltip elem : tooltips) {
                // Prevent from drawing more than 4 tooltips.
                if (count > 3)
                    break;
                // Render the tooltip.
                renderTooltip(fontRenderer, matrices, y - screenBorder - (12 * count), color, elem.getTooltipText().formatted(Formatting.GRAY));
                count++;
            }
            // show the "and x more..." tooltip if the item has more than 4 tooltips.
            if (showMoreTooltip)
                renderTooltip(fontRenderer, matrices, y - screenBorder, color, new TranslatableText("container.shulkerBox.more", tooltips.size() - 4).formatted(Formatting.GRAY));
        } else if (settings.getHeldItemTooltip() == 2) {
            // draw the background
            renderBackground(matrices, y, screenBorder, tooltipOffset, fontRenderer.getWidth(text));
        }
    }
    // Render the item name.
    return fontRenderer.drawWithShadow(matrices, text, x, y - tooltipOffset - screenBorder, color);
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) BedrockifySettings(me.juancarloscp52.bedrockify.BedrockifySettings) PotionTooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.PotionTooltip) EnchantmentTooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.EnchantmentTooltip) Tooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.Tooltip) ShulkerBoxTooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.ShulkerBoxTooltip)

Example 5 with Tooltip

use of me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.Tooltip in project BedrockIfy by juancarloscp52.

the class HeldItemTooltips method equals.

/**
 * Checks if the tooltips of two items are equal.
 */
public boolean equals(ItemStack item1, ItemStack item2) {
    List<Tooltip> itemTooltips1 = getTooltips(item1);
    List<Tooltip> itemTooltips2 = getTooltips(item2);
    if (itemTooltips1 == null && itemTooltips2 == null)
        return true;
    else if (itemTooltips1 == null || itemTooltips2 == null)
        return false;
    if (itemTooltips1.size() != itemTooltips2.size())
        return false;
    Iterator<Tooltip> iterator1 = itemTooltips1.iterator();
    Iterator<Tooltip> iterator2 = itemTooltips2.iterator();
    while (iterator1.hasNext()) {
        Tooltip tooltip1 = iterator1.next();
        Tooltip tooltip2 = iterator2.next();
        if (!tooltip1.getTooltipText().equals(tooltip2.getTooltipText()))
            return false;
    }
    return true;
}
Also used : PotionTooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.PotionTooltip) EnchantmentTooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.EnchantmentTooltip) Tooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.Tooltip) ShulkerBoxTooltip(me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.ShulkerBoxTooltip)

Aggregations

EnchantmentTooltip (me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.EnchantmentTooltip)4 PotionTooltip (me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.PotionTooltip)4 ShulkerBoxTooltip (me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.ShulkerBoxTooltip)4 Tooltip (me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.Tooltip.Tooltip)4 ItemStack (net.minecraft.item.ItemStack)2 TranslatableText (net.minecraft.text.TranslatableText)2 ArrayList (java.util.ArrayList)1 BedrockifySettings (me.juancarloscp52.bedrockify.BedrockifySettings)1 HeldItemTooltips (me.juancarloscp52.bedrockify.client.features.HeldItemTooltips.HeldItemTooltips)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1