Skip to content

Commit

Permalink
Fix 1.21->1.20.5 enchantment lore format and add show_in_tooltip check
Browse files Browse the repository at this point in the history
Fixes #877
  • Loading branch information
kennytv committed Aug 29, 2024
1 parent 47b1508 commit db47040
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public void rewriteEnchantmentsToClient(final StructuredDataContainer data, fina

final Enchantments enchantments = enchantmentsData.value();
final List<Tag> loreToAdd = new ArrayList<>();
boolean changed = false;
boolean updatedLore = false;
boolean removedEnchantments = false;

final ObjectIterator<Int2IntMap.Entry> iterator = enchantments.enchantments().int2IntEntrySet().iterator();
final List<PendingIdChange> updatedIds = new ArrayList<>();
Expand All @@ -101,13 +102,15 @@ public void rewriteEnchantmentsToClient(final StructuredDataContainer data, fina
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);
Expand All @@ -123,8 +126,7 @@ public void rewriteEnchantmentsToClient(final StructuredDataContainer data, fina
enchantments.add(change.mappedId(), change.level());
}

if (loreToAdd.isEmpty()) {
// No removed enchantments
if (!removedEnchantments) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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;
Expand Down Expand Up @@ -177,6 +178,8 @@ public Item handleItemToClient(final UserConnection connection, final Item item)
}

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

Expand Down

0 comments on commit db47040

Please sign in to comment.