From db470405430a763cf666db18775836c5b1da8280 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 29 Aug 2024 19:18:43 +0200 Subject: [PATCH] Fix 1.21->1.20.5 enchantment lore format and add show_in_tooltip check Fixes #877 --- .../rewriters/StructuredEnchantmentRewriter.java | 14 ++++++++------ .../rewriter/BlockItemPacketRewriter1_21.java | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java index 900cfb2d..9a53020e 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java @@ -84,7 +84,8 @@ public class StructuredEnchantmentRewriter { final Enchantments enchantments = enchantmentsData.value(); final List loreToAdd = new ArrayList<>(); - boolean changed = false; + boolean updatedLore = false; + boolean removedEnchantments = false; final ObjectIterator iterator = enchantments.enchantments().int2IntEntrySet().iterator(); final List updatedIds = new ArrayList<>(); @@ -101,13 +102,15 @@ public class StructuredEnchantmentRewriter { continue; } + removedEnchantments = true; + final Tag description = descriptionSupplier.get(id, level); - if (description != null) { - if (!changed) { + if (description != null && enchantments.showInTooltip()) { + if (!updatedLore) { // Backup original before doing modifications final CompoundTag customData = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value(); itemRewriter.saveListTag(customData, asTag(enchantments), key.identifier()); - changed = true; + updatedLore = true; } loreToAdd.add(description); @@ -123,8 +126,7 @@ public class StructuredEnchantmentRewriter { enchantments.add(change.mappedId(), change.level()); } - if (loreToAdd.isEmpty()) { - // No removed enchantments + if (!removedEnchantments) { return; } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java index 933fb0be..f86bceef 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_21to1_20_5/rewriter/BlockItemPacketRewriter1_21.java @@ -38,6 +38,7 @@ import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; import com.viaversion.viaversion.api.type.types.version.Types1_20_5; import com.viaversion.viaversion.api.type.types.version.Types1_21; import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap; +import com.viaversion.viaversion.libs.mcstructs.core.TextFormatting; import com.viaversion.viaversion.libs.mcstructs.text.components.StringComponent; import com.viaversion.viaversion.libs.mcstructs.text.components.TranslationComponent; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3; @@ -177,6 +178,8 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRe } final var component = SerializerVersion.V1_20_5.toComponent(description); + component.getStyle().setItalic(false); + component.getStyle().setFormatting(TextFormatting.GRAY); component.getSiblings().add(new StringComponent(" ")); component.getSiblings().add(new TranslationComponent(EnchantmentRewriter.ENCHANTMENT_LEVEL_TRANSLATION.formatted(level)));