Cold Sweat

Cold Sweat

3M Downloads

Custom item names shift the insulation tooltip

SiverDX opened this issue ยท 4 comments

commented

image

image

See

// Get the index at which the tooltip should be inserted
int tooltipIndex = Math.min(1, event.getTooltipElements().size() - 1);
Optional<FormattedText> line;
while ((line = event.getTooltipElements().get(tooltipIndex).left()).isPresent()
&& !line.get().equals(stack.getDisplayName()))
{ tooltipIndex++;
if (tooltipIndex >= event.getTooltipElements().size())
{ tooltipIndex = Math.min(1, event.getTooltipElements().size());
break;
}
}

empty[style={color=white}, siblings=[translation{key='misc.apotheosis.affix_name.three', args=[translation{key='affix.irons_spellbooks:armor/attribute/mana', args=[]}[style={}], translation{key='item.minecraft.leather_helmet', args=[]}, translation{key='affix.apotheosis:armor/attribute/stalwart.suffix', args=[]}[style={}]]}[style={color=#ED7014}]]]
commented

Might only occur with https://www.curseforge.com/minecraft/mc-mods/apotheosis since anvil renames stores the name in a tag

commented

I'm not sure why this might be happening. I can't seem to recreate the issue
image

It could be that other mod that adds all the other information like durability, protection, etc at the top of the tooltip

commented

It's from Obscure API but if you disable it:

image

commented

Figured it out, this only happens in 1.19. I was testing in 1.20. I believe this is happening because I was using ItemStack#getDisplayName() to find the line where the item's name is, when I should have been using ItemStack#getHoverName().
It seems like the first one just gets the item's name from NBT (which would work for anvil-named items, as you mentioned, but not names set by other means), and the second one actually returns the item's name as it is displayed.

I also figured out that directly comparing Components isn't the way to go, since they don't have a custom equals() method and it just compares the hash, which can be fickle. I decided to compare the string representation of the lines and had better results.