Is it possible to add components/bars to the HUD Minecraft Java 1.19.x



  • I am trying to make a survival datapack that would require you to drink water. Is it possible to add an element to the HUD to indicate how much water you need based on a scoreboard value? I did some research and it might be possible with Spigot, and I would like to stay with vanilla commands but I would be OK with using Spigot/Fabric. I don't really want to use Forge because of optimization/performance reasons.



  • Preface: I do not understand how to solve this problem, but I know of a video where someone can describe it in detail.


    You can use custom fonts, as shown in this video:

    I'll summarize it here:

    The game recognizes Unicode characters, such as this delete character:

    tellraw @s {"text":"\u0010"}
    

    However, The game only recognizes a certain amount of Unicode characters. So, you can use a resourcepack to replace the unused characters with an image file of your own. These unused characters range from \uE000 to \uFFFF, in hexadecimal.

    Here is an example of a font file, located in assets > minecraft > font > default.json:

    {
        "providers": [
            {
                "type": "bitmap",
                "file": "minecraft:custom/icon.png",
                "ascent": 2,
                "height": 27,
                "chars": ["\uE000"]
            },
            {
                "type": "bitmap",
                "file": "minecraft:custom/icon_half.png",
                "ascent": 2,
                "height": 27,
                "chars": ["\uE001"]
            },
            {
                "type": "bitmap",
                "file": "minecraft:custom/icon_off.png",
                "ascent": 2,
                "height": 27,
                "chars": ["\uE002"]
            }
        ]
    }
    

    By displaying these characters in the actionbar, it starts to resemble a custom bar. To position the character properly (such as above the hearts), you have to modify the "ascent" and "height" values of the character such that they are displaced to the area of the screen you want. This can also change the size of the character.

    To help position the characters properly, you'll probably need a negative space font character: https://github.com/AmberWat/NegativeSpaceFont


    Sorry I didn't explain too clearly, this is not my area of expertise. If anyone knows better than I, please edit! I hope this helped guide your efforts.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2