mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-20 16:37:48 +01:00
More cleanup to structured enchantment rewriter
This commit is contained in:
parent
678775ab9d
commit
4066b9b52b
@ -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) {
|
||||||
|
// Backup original before doing modifications
|
||||||
|
final CompoundTag customData = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value();
|
||||||
|
itemRewriter.saveListTag(customData, asTag(enchantments), key.identifier());
|
||||||
|
removedEnchantments = true;
|
||||||
|
}
|
||||||
|
|
||||||
final Tag description = descriptionSupplier.get(id, level);
|
final Tag description = descriptionSupplier.get(id, level);
|
||||||
if (description != null && enchantments.showInTooltip()) {
|
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());
|
|
||||||
updatedLore = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
loreToAdd.add(description);
|
loreToAdd.add(description);
|
||||||
|
updatedLore = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,37 +126,37 @@ public class StructuredEnchantmentRewriter {
|
|||||||
enchantments.add(change.mappedId(), change.level());
|
enchantments.add(change.mappedId(), change.level());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!removedEnchantments) {
|
if (removedEnchantments) {
|
||||||
return;
|
final CompoundTag tag = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value();
|
||||||
}
|
if (!storedEnchant && enchantments.size() == 0) {
|
||||||
|
// Add glint override if there are no enchantments left
|
||||||
// Add glint override if there are no enchantments left
|
final StructuredData<Boolean> glintOverride = data.getNonEmpty(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE);
|
||||||
final CompoundTag tag = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value();
|
if (glintOverride != null) {
|
||||||
if (!storedEnchant && enchantments.size() == 0) {
|
tag.putBoolean(itemRewriter.nbtTagName("glint"), glintOverride.value());
|
||||||
final StructuredData<Boolean> glintOverride = data.getNonEmpty(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE);
|
} else {
|
||||||
if (glintOverride != null) {
|
tag.putBoolean(itemRewriter.nbtTagName("noglint"), true);
|
||||||
tag.putBoolean(itemRewriter.nbtTagName("glint"), glintOverride.value());
|
}
|
||||||
} else {
|
data.set(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, true);
|
||||||
tag.putBoolean(itemRewriter.nbtTagName("noglint"), true);
|
}
|
||||||
|
|
||||||
|
if (enchantments.showInTooltip()) {
|
||||||
|
tag.putBoolean(itemRewriter.nbtTagName("show_" + key.identifier()), true);
|
||||||
}
|
}
|
||||||
data.set(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save original lore
|
if (updatedLore) {
|
||||||
final StructuredData<Tag[]> loreData = data.getNonEmpty(StructuredDataKey.LORE);
|
// Save original lore
|
||||||
if (loreData != null) {
|
final CompoundTag tag = data.computeIfAbsent(StructuredDataKey.CUSTOM_DATA, $ -> new CompoundTag()).value();
|
||||||
final List<Tag> loreList = Arrays.asList(loreData.value());
|
final StructuredData<Tag[]> loreData = data.getNonEmpty(StructuredDataKey.LORE);
|
||||||
itemRewriter.saveGenericTagList(tag, loreList, "lore");
|
if (loreData != null) {
|
||||||
loreToAdd.addAll(loreList);
|
final List<Tag> loreList = Arrays.asList(loreData.value());
|
||||||
} else {
|
itemRewriter.saveGenericTagList(tag, loreList, "lore");
|
||||||
tag.putBoolean(itemRewriter.nbtTagName("nolore"), true);
|
loreToAdd.addAll(loreList);
|
||||||
|
} else {
|
||||||
|
tag.putBoolean(itemRewriter.nbtTagName("nolore"), true);
|
||||||
|
}
|
||||||
|
data.set(StructuredDataKey.LORE, loreToAdd.toArray(new Tag[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enchantments.showInTooltip()) {
|
|
||||||
tag.putBoolean(itemRewriter.nbtTagName("show_" + key.identifier()), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
data.set(StructuredDataKey.LORE, loreToAdd.toArray(new Tag[0]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ListTag<CompoundTag> asTag(final Enchantments enchantments) {
|
private ListTag<CompoundTag> asTag(final Enchantments enchantments) {
|
||||||
|
Loading…
Reference in New Issue
Block a user