Skip to content

Conversation

@AjaxGb
Copy link
Contributor

@AjaxGb AjaxGb commented Feb 20, 2025

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.

Convert negative integers to unsigned integers. Truncate the alpha from colors before passing them to the HTML color picker, since it doesn't allow alpha values (and they'd be in the wrong place if it did).
@vercel
Copy link

vercel bot commented Feb 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
misode ✅ Ready (Inspect) Visit Preview Feb 20, 2025 1:15am

@misode
Copy link
Owner

misode commented Feb 21, 2025

Is this correct? Does the game also show the alpha channel in hex here?
image

@AjaxGb
Copy link
Contributor Author

AjaxGb commented Feb 22, 2025

Yes it does:
image
And it does not handle leading zeroes for it, which I also emulated (even though it looks stupid and is probably a bug):
image

@misode misode merged commit 3f52a90 into misode:master Feb 22, 2025
1 check passed
@AjaxGb AjaxGb deleted the fix-color-picker branch February 22, 2025 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants