mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-18 16:17:45 +01:00
Fix 1.21->1.20.5 enchantment lore format and add show_in_tooltip check
Fixes #877
This commit is contained in:
parent
47b1508f66
commit
db47040543
@ -84,7 +84,8 @@ public class StructuredEnchantmentRewriter {
|
||||
|
||||
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<>();
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user