3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-11-16 04:50:10 +01:00

More cleanup to structured enchantment rewriter

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-08-29 19:53:47 +02:00
Ursprung 678775ab9d
Commit 4066b9b52b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F

Datei anzeigen

@ -84,8 +84,8 @@ public class StructuredEnchantmentRewriter {
final Enchantments enchantments = enchantmentsData.value(); final Enchantments enchantments = enchantmentsData.value();
final List<Tag> loreToAdd = new ArrayList<>(); final List<Tag> loreToAdd = new ArrayList<>();
boolean updatedLore = false;
boolean removedEnchantments = false; boolean removedEnchantments = false;
boolean updatedLore = false;
final ObjectIterator<Int2IntMap.Entry> iterator = enchantments.enchantments().int2IntEntrySet().iterator(); final ObjectIterator<Int2IntMap.Entry> iterator = enchantments.enchantments().int2IntEntrySet().iterator();
final List<PendingIdChange> updatedIds = new ArrayList<>(); final List<PendingIdChange> updatedIds = new ArrayList<>();
@ -102,19 +102,19 @@ public class StructuredEnchantmentRewriter {
continue; continue;
} }
removedEnchantments = true; if (!removedEnchantments) {
final Tag description = descriptionSupplier.get(id, level);
if (description != null && enchantments.showInTooltip()) {
if (!updatedLore) {
// Backup original before doing modifications // Backup original before doing modifications
final CompoundTag customData = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value(); final CompoundTag customData = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value();
itemRewriter.saveListTag(customData, asTag(enchantments), key.identifier()); itemRewriter.saveListTag(customData, asTag(enchantments), key.identifier());
removedEnchantments = true;
}
final Tag description = descriptionSupplier.get(id, level);
if (description != null && enchantments.showInTooltip()) {
loreToAdd.add(description);
updatedLore = true; updatedLore = true;
} }
loreToAdd.add(description);
}
iterator.remove(); iterator.remove();
} }
@ -126,13 +126,10 @@ public class StructuredEnchantmentRewriter {
enchantments.add(change.mappedId(), change.level()); enchantments.add(change.mappedId(), change.level());
} }
if (!removedEnchantments) { if (removedEnchantments) {
return;
}
// Add glint override if there are no enchantments left
final CompoundTag tag = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value(); final CompoundTag tag = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value();
if (!storedEnchant && enchantments.size() == 0) { if (!storedEnchant && enchantments.size() == 0) {
// Add glint override if there are no enchantments left
final StructuredData<Boolean> glintOverride = data.getNonEmpty(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE); final StructuredData<Boolean> glintOverride = data.getNonEmpty(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE);
if (glintOverride != null) { if (glintOverride != null) {
tag.putBoolean(itemRewriter.nbtTagName("glint"), glintOverride.value()); tag.putBoolean(itemRewriter.nbtTagName("glint"), glintOverride.value());
@ -142,7 +139,14 @@ public class StructuredEnchantmentRewriter {
data.set(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, true); data.set(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, true);
} }
if (enchantments.showInTooltip()) {
tag.putBoolean(itemRewriter.nbtTagName("show_" + key.identifier()), true);
}
}
if (updatedLore) {
// Save original lore // Save original lore
final CompoundTag tag = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value();
final StructuredData<Tag[]> loreData = data.getNonEmpty(StructuredDataKey.LORE); final StructuredData<Tag[]> loreData = data.getNonEmpty(StructuredDataKey.LORE);
if (loreData != null) { if (loreData != null) {
final List<Tag> loreList = Arrays.asList(loreData.value()); final List<Tag> loreList = Arrays.asList(loreData.value());
@ -151,13 +155,9 @@ public class StructuredEnchantmentRewriter {
} else { } else {
tag.putBoolean(itemRewriter.nbtTagName("nolore"), true); tag.putBoolean(itemRewriter.nbtTagName("nolore"), true);
} }
if (enchantments.showInTooltip()) {
tag.putBoolean(itemRewriter.nbtTagName("show_" + key.identifier()), true);
}
data.set(StructuredDataKey.LORE, loreToAdd.toArray(new Tag[0])); data.set(StructuredDataKey.LORE, loreToAdd.toArray(new Tag[0]));
} }
}
private ListTag<CompoundTag> asTag(final Enchantments enchantments) { private ListTag<CompoundTag> asTag(final Enchantments enchantments) {
final ListTag<CompoundTag> listTag = new ListTag<>(CompoundTag.class); final ListTag<CompoundTag> listTag = new ListTag<>(CompoundTag.class);