Fix handling of colors with alpha in color pickers and item tooltips #705
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



Currently, color values with non-zero alpha are not handled correctly. If there is any alpha, the color picker will always be black. If the alpha is high enough to make the color value negative, tooltips also display incorrectly. (Many vanilla files contain 0xFF alpha, making the color value negative.)
This PR fixes both issues. For use with the color picker, alpha is truncated completely, since the HTML color picker doesn't support alpha, and Minecraft's dye system ignores it anyway. For display in the tooltip, negative integers are correctly converted to unsigned integers. Also capitalizes the hexadecimal in tooltips, to match the behavior in the game.
Example loot table:
{ "pools": [ { "rolls": 1, "entries": [ { "type": "minecraft:item", "name": "minecraft:leather_helmet", "functions": [ { "function": "minecraft:set_components", "components": { "minecraft:dyed_color": -16721153 } } ] } ] }, { "rolls": 1, "entries": [ { "type": "minecraft:item", "name": "minecraft:leather_boots", "functions": [ { "function": "minecraft:set_components", "components": { "minecraft:dyed_color": 251714303 } } ] } ] } ] }Helmet: 0xff alpha, resulting in negative color value. Tooltip contains a minus sign in a weird place, color picker is broken.
Boots: 0x0f alpha, resulting in positive color value. Tooltip is okay (although it should be uppercase to match the actual game), color picker is still broken.