Skip to content

Commit f4bc485

Browse files
committed
Only create custom data tag in enchantment rewriter if necessary
1 parent b4a4b54 commit f4bc485

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

common/src/main/java/com/viaversion/viabackwards/api/rewriters/StructuredEnchantmentRewriter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ public void handleToServer(final Item item) {
7878

7979
public void rewriteEnchantmentsToClient(final StructuredDataContainer data, final StructuredDataKey<Enchantments> key, final IdRewriteFunction rewriteFunction, final DescriptionSupplier descriptionSupplier, final boolean storedEnchant) {
8080
final StructuredData<Enchantments> enchantmentsData = data.getNonEmpty(key);
81-
if (enchantmentsData == null) {
81+
if (enchantmentsData == null || enchantmentsData.value().size() == 0) {
8282
return;
8383
}
8484

85-
final CompoundTag tag = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value();
8685
final Enchantments enchantments = enchantmentsData.value();
8786
final List<Tag> loreToAdd = new ArrayList<>();
8887
boolean changed = false;
@@ -106,7 +105,8 @@ public void rewriteEnchantmentsToClient(final StructuredDataContainer data, fina
106105
if (description != null) {
107106
if (!changed) {
108107
// Backup original before doing modifications
109-
itemRewriter.saveListTag(tag, asTag(enchantments), key.identifier());
108+
final CompoundTag customData = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value();
109+
itemRewriter.saveListTag(customData, asTag(enchantments), key.identifier());
110110
changed = true;
111111
}
112112

@@ -129,6 +129,7 @@ public void rewriteEnchantmentsToClient(final StructuredDataContainer data, fina
129129
}
130130

131131
// Add glint override if there are no enchantments left
132+
final CompoundTag tag = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value();
132133
if (!storedEnchant && enchantments.size() == 0) {
133134
final StructuredData<Boolean> glintOverride = data.getNonEmpty(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE);
134135
if (glintOverride != null) {

0 commit comments

Comments
 (0)