Search in sources :

Example 1 with EnchantedBookItem

use of net.minecraft.item.EnchantedBookItem 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 2 with EnchantedBookItem

use of net.minecraft.item.EnchantedBookItem in project Biome-Makeover by Lemonszz.

the class AltarBlockEntity method isValidForCurse.

public static boolean isValidForCurse(ItemStack stack) {
    if (stack.isEmpty() || stack.getItem() instanceof EnchantedBookItem)
        return false;
    if (stack.getItem() == Items.BOOK)
        return true;
    Map<Enchantment, Integer> enchantments = EnchantmentHelper.get(stack);
    if (enchantments.isEmpty() || (stack.hasTag() && stack.getTag().contains("BMCursed")))
        return false;
    boolean hasNewCompatibleCurse = false;
    for (Enchantment enchantment : enchantments.keySet()) {
        if (enchantment.getMaxLevel() > 1 && !enchantment.isCursed())
            return true;
        if (enchantment.isCursed() && enchantment.isAcceptableItem(stack) && !enchantments.containsKey(enchantment))
            hasNewCompatibleCurse = true;
    }
    return hasNewCompatibleCurse;
}
Also used : EnchantedBookItem(net.minecraft.item.EnchantedBookItem) Enchantment(net.minecraft.enchantment.Enchantment)

Aggregations

EnchantedBookItem (net.minecraft.item.EnchantedBookItem)2 TextRenderer (net.minecraft.client.font.TextRenderer)1 Enchantment (net.minecraft.enchantment.Enchantment)1 ListTag (net.minecraft.nbt.ListTag)1 LiteralText (net.minecraft.text.LiteralText)1 Text (net.minecraft.text.Text)1 TranslatableText (net.minecraft.text.TranslatableText)1