#appendTooltip gives outdated results

16 messages · Page 1 of 1 (latest)

drowsy wraith
#

Hi. I have an ItemStack with a Component that gets changed mid-gameplay. When I go to check the Tooltip that displays the ItemStack's Component data, it is outdated, displaying instead the last-displayed Tooltip. Logging my override of appendTooltip shows that the ItemStack being passed is an old version of the actual stack in inventory, and it only corrects after clicking the ItemStack or dropping it. I believe this is most likely an error of my doing, but I cannot find a solution.

For context, here is my repo:
https://github.com/Ginleaff/Mavila/tree/master/mavila-quiver/src/main/java/mod/ginleaf/quiver

Thanks.

GitHub

A Multi-Mod that contains some Micro-Mods for Fabric 1.21+ [Placer, Railings, Quiver, etc...] - Ginleaff/Mavila

steel abyss
#

additionally, and its 99.999% that its not causing problems, but... you dont seem to be checking sidedness in your click methods

drowsy wraith
#

Yeah they don't need to be saved. Source for the Bundle which I based a lot of it on also doesn't check for sides.

steel abyss
#

also you are comparing itemstacks using stack.equals which does not take into account count

drowsy wraith
#

Oh what should I be using?

steel abyss
#

areEqual

drowsy wraith
#

Okay.

drowsy wraith
#

I should add that the ItemStack in inventory itself isn't faulty. It saves correctly, correctly shows updated data on world load, and logging shows it has the correct data. It just differs from the ItemStack passed into the appendTooltip method.

steel abyss
#

the appendTooltip one is on render thread. that means its not syncing to client, likely because its not marking the component as changed, likely because the change in item count doesnt change the .equals or hashcode of your component

#

component is the same, so no update needed

drowsy wraith
steel abyss
#

yes, and probably need to update your hashCode method as well

drowsy wraith
#

Gotcha, I'll get on that in a little bit. Thank you.

drowsy wraith
#

Okay, I did as you said. It works at first when I use the ItemStack, updating the Tooltip once, but it then locks up and permanently matches again. Somehow the passed object is updating with the ItemStack, but I could be wrong. The culprit is purely .equals(), setting it to be permanently false fixes the issue. I've been trying to diagnose what went wrong, but it's late, this is what I've got right now.

steel abyss
#

I would change the last line

return ItemStack.stacksEqual(this.stacks, bundleComponent.stacks)

just for clarity i would also change the size comparison
if (this.size() != bundleComponent.size()) return false;