Curios API (Forge/NeoForge)

Curios API (Forge/NeoForge)

204M Downloads

Attribute Modifier Tooltip Display Issue

Pandaismyname1 opened this issue · 6 comments

commented

Context:

Curios: 5.11.1
Minecraft: 1.20.1
Forge: 47.2.20

I am working on a mod to power up items. Some of those items happen to be Curios, and they need to have Attribute Modifiers applied to them. They already have attribute modifiers, and the new ones that I wish to add are calculated based on existing ones.

I am keeping the logic simple, by subscribing to the CurioAttributeModifierEvent event, and handling the attribute modification from there.

    @SubscribeEvent(priority = EventPriority.HIGHEST)
    public static void onCuriosAttributes(CurioAttributeModifierEvent event) {
        var stack = event.getItemStack();
        var isValidItem = ItemValidator.isItemUpgradeable(stack);
        if (!isValidItem) {
            return;
        }
        var itemLevel = Upgrader.getItemLevel(stack);
        if (itemLevel == 0) {
            return;
        }
        var modifications = UpgradeCalculator.calculateUpgrade(stack, null, itemLevel, event.getOriginalModifiers());
        modifications.forEach(event::addModifier);
    }

Issue:

Now the item has 2 attribute modifiers (one from the item, as the developer of the item intended), and one that is my own. Both have the same Operation.

The issue is that the display of the tooltip is constantly reordering the display components for the attributes. Here's a short video showcasing the glitch.

Screen.Recording.2025-02-01.082339.mp4

Additional Notes:

  • The item in question is a spellbook from Iron's Spells & Spellbooks, but the issue is valid for ANY curio item, so I would love to see this fixed, as it is only a display problem (serverside, the order of attributes does not matter that much).
  • UpgradeCalculator.calculateUpgrade does not edit the original modifiers, just reads from them.
  • Please keep updating it for 1.20.1 <3
  • Event Priority is irrelevant, tried it with other values, same behavior
  • For best compatibility with other mods, I think the best solution is to collapse the attribute modifiers in the tooltip (eg.: all minecraft:generic_attack_damage that are ADDITION should be displayed in a single line as a sum)
commented

Are you making sure to use event.getUuid() or any static ones for the UUID of your additional attribute modifiers? I believe that, if you try to use random UUIDs, it will cause this sort of fluctuating tooltip behavior.

commented

In this case I am not using preset UUIDs, to allow the attributes to work on multiple curios slots. If I would use preset UUIDs, the modifiers will collide with each other when 2 or more items of the same type and same curio type would be located in the different slots of the same type, as per Curios documentation.

commented

If you use event.getUuid() from the CurioAttributeModifierEvent, it will not cause collision issues. The UUID provided from that is slot-specific and will allow the attributes to work in multiple slots.

commented

Ah okay, thank you for your detailed report. I misunderstood the original issue, so my apologies for that. I see what you mean now and I'll look into what can be done about this.

commented

Will try it out shortly, and come back with feedback.

commented

Okay, I have some really easy reproduction scenarios:

Prereq:

  1. Use Iron's Spells Mod (we need some curio to test this on, but this applies to all curios that have attribute modifiers)
  2. Get a book(they are curios) has an attribute modifier with adition on attribute max_mana
  3. Test each case, see behavior

Case 1: Using Static UUID

    public static void onCuriosAttributes(CurioAttributeModifierEvent event) {
        var attributeRegistry = ForgeRegistries.ATTRIBUTES;
        var max_mana = attributeRegistry.getValue(new ResourceLocation("irons_spellbooks:max_mana"));
        var uuid = UUID.fromString("fd5034db-6166-4b41-9bfb-f47b619c9e2c");
        event.addModifier(max_mana, new AttributeModifier(uuid,  "MANASSSS", 2, AttributeModifier.Operation.ADDITION));
    }

This will result in wild flickering, because there are 2 mana attributes with addition

Case 2: Using Random UUID

    public static void onCuriosAttributes(CurioAttributeModifierEvent event) {
        var attributeRegistry = ForgeRegistries.ATTRIBUTES;
        var max_mana = attributeRegistry.getValue(new ResourceLocation("irons_spellbooks:max_mana"));
        event.addModifier(max_mana, new AttributeModifier(UUID.randomUUID(), "MANASSSS", 2, AttributeModifier.Operation.ADDITION));
    }

This will result in wild flickering, because there are 2 mana attributes with addition

Case 3: Using Event's UUID

    public static void onCuriosAttributes(CurioAttributeModifierEvent event) {
        var attributeRegistry = ForgeRegistries.ATTRIBUTES;
        var max_mana = attributeRegistry.getValue(new ResourceLocation("irons_spellbooks:max_mana"));
        event.addModifier(max_mana, new AttributeModifier(event.getUuid(), "MANASSSS", 2, AttributeModifier.Operation.ADDITION));
    }

This will not add our newly registered attribute modifier, and will have ONLY the base attributes for the curio in question.

Desired Behavior:

Have the following code work without any flickering in the tooltip UI.

    public static void onCuriosAttributes(CurioAttributeModifierEvent event) {
        var attributeRegistry = ForgeRegistries.ATTRIBUTES;
        var max_mana = attributeRegistry.getValue(new ResourceLocation("irons_spellbooks:max_mana"));
        var uuid = UUID.fromString("fd5034db-6166-4b41-9bfb-f47b619c9e2c");
        event.addModifier(max_mana, new AttributeModifier(uuid,  "MANASSSS", 2, AttributeModifier.Operation.ADDITION));
    }