Skip to content

Commit 424face

Browse files
committed
fix(EnchantManager): add string fallback for tooltip cache validation
1 parent b7b5f42 commit 424face

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/main/java/com/fix3dll/skyblockaddons/features/enchants/EnchantManager.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ static class Cache {
395395
static final int MISSING_ENCHANTS_PER_LINE = 3;
396396

397397
private ArrayList<Component> cachedBefore = new ArrayList<>();
398+
private ArrayList<String> cachedBeforeStrings = new ArrayList<>();
398399
@Getter ArrayList<Component> cachedAfter = new ArrayList<>();
399400
boolean configChanged = false;
400401
Set<FormattedEnchant> formattedEnchants = Collections.emptySet();
@@ -421,6 +422,10 @@ public Cache() {
421422
*/
422423
public void updateBefore(List<Component> loreBeforeModifications, ItemStack itemStack) {
423424
cachedBefore = new ArrayList<>(loreBeforeModifications);
425+
this.cachedBeforeStrings = new ArrayList<>(loreBeforeModifications.size());
426+
for (Component line : loreBeforeModifications) {
427+
this.cachedBeforeStrings.add(line.getString());
428+
}
424429
this.itemStack = itemStack;
425430
formattedEnchants = Collections.emptySet();
426431
missingEnchants = null;
@@ -576,9 +581,9 @@ public List<Component> getMissingEnchantsComponent() {
576581

577582
/**
578583
* Returns {@code true} if the cache entry is valid for the given lore list and item.
579-
* Checks {@link ItemStack} identity, lore size, and element identity via {@code !=}, since
580-
* component equality is reference-based. The element check catches the edge case where
581-
* another mod replaces a component at an existing index without changing list size.
584+
* <p>
585+
* Validates the item identity, lore size, and line contents. It uses a fast reference check
586+
* followed by a pre-calculated string comparison to maintain performance and handle edge cases.
582587
* @param loreList the unmodified lore list passed to {@link EnchantManager#parseEnchants}
583588
* @param itemStack the item being rendered
584589
* @return {@code true} if the stored post-parse result can be reused, {@code false} otherwise
@@ -588,7 +593,12 @@ public boolean isCached(List<Component> loreList, ItemStack itemStack) {
588593
return false;
589594
}
590595
for (int i = 0; i < loreList.size(); i++) {
591-
if (loreList.get(i) != cachedBefore.get(i)) {
596+
Component currentLine = loreList.get(i);
597+
Component cachedLine = cachedBefore.get(i);
598+
if (currentLine == cachedLine) {
599+
continue;
600+
}
601+
if (!loreList.get(i).getString().equals(cachedBeforeStrings.get(i))) {
592602
return false;
593603
}
594604
}

0 commit comments

Comments
 (0)