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);
}
}
}
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;
}
Aggregations