Just Enough Items (JEI)

Just Enough Items (JEI)

495M Downloads

[Bug/Feature Request]: IRecipeSlotRichTooltipCallback is insufficient for adjusting fluid stack amount displays

KnightMiner opened this issue ยท 7 comments

commented

Other

Overview of Problem

Since some time before 1.12, Tinkers' Construct has displayed fluid amounts in JEI formatted using our fluid units. For example, an ingot is displayed as "1 ingot" instead of "90 mb". This feature both provides parity with our UIs, and greatly improves the user experience as they are not required to do math or lookup other recipes to find the equivalent amount of items to perform a recipe.

To accomplish this, we typically remove the fluid amount display line, then add in our own fluid amount lines using our tooltip handler. This will show units, or show mb when holding shift. It is important that we remove the JEI added mb display as our tooltip handler falls back to mb if no unit matches an amount, making the unit display confusing if both are shown at the same time.

Since JEI 19.8.5, IRecipeSlotTooltipCallback was deprecated in favor of IRecipeSlotRichTooltipCallback. However, the latter is insufficient for our needs as it features no (non deprecated) way to remove tooltip lines.

Suggested fixes

One possible fix would be allowing us to continue removing specific lines from the tooltip, though I suspect there is a reason JEI doesn't want that feature to remain.

Another fix would be a method to suppress just the amount from the tooltip. This would additionally be useful beyond our usage in unit display for when catalysts are involved in recipes, such as the fuels we display in some recipes. These catalysts don't need to display an amount as no amount is really relevant.

A third potential fix is adding a fluid unit formatter API on a per fluid basis, something that maps a fluid stack to a component or a list of components for unit display. We can either manually setup our "Hold Shift for mb" function or let JEI handle that and we just supply non-MB display/a boolean stating if we just displayed in MB. One downside to this option is my fluid formatter supports formatting fluids that are not added by my mod, so there may be conflicts between my desire to display them in relevant units and JEI wanting to allow other mods to register them.

Affected Versions

For 1.20 and 1.21, we can continue to use the deprecated API to accomplish what we want. This problem is mainly an issue for the future of JEI whenever the deprecated API is removed.

Ideally, a fix would be implemented as far back as 1.20 though, as that will let us validate that the fix suits our needs.

Screenshots

Below is a picture of the desired behavior in Tinkers' JEI

Image

commented

Create is facing a similar problem. Rich callbacks are only able to append to the end of the tooltip, while the deprecated API can add lines anywhere.

This looks terrible for potion fluids, and doesn't match vanilla potion items.

Image
Image

commented

That create example seems like a good case for a fluid specific tooltip callbacks, as ideally you'd want that info on every instance of your fluid in JEI, not just your recipes.

Though we really would benefit from a forge/neo hook for that

commented

This has been automatically marked as stale because it has not had recent activity, and will be closed if no further activity occurs. If this was overlooked, forgotten, or should remain open for any other reason, please reply here to call attention to it and remove the stale status. Thank you for your contributions.

commented

To my knowledge no action has been taken regarding this issue, and thus its still relevant.

commented

Sorry for not updating this.
In 1.21.5 I have removed the old deprecated tooltip callbacks, and added support for directly modifying the rich tooltip in any way you like:

/**
* Get the lines stored by this tooltip builder.
* These lines are directly modifiable.
*
* @since 21.1.0
*/
List<Either<FormattedText, TooltipComponent>> getLines();

I assume you still want this backported though, and I can work on it so that you have a cleaner upgrade path.

commented

That sounds good to allow us to continue doing what we were doing before. Thanks for the update.

Do you think it's worth JEI adding a more specific API for fluid units or for extra tooltip information on fluids? Or would you rather see that added to Neo/Fabric? This would be with the intention that my fluid ingredient in my recipes shows the same as the same fluid in another mods recipes

commented

I have backported the improvements to 1.21.1 in version 19.22.0.x ๐Ÿ‘

I think the fluid information may be better if it's built into the mod loader, similar to how ItemStack is handled right now in vanilla. That would probably allow more control over how things are rendered and ordered in the tooltip.