Jump to content

Recommended Posts

Posted

I've got working code to render a tooltip, and I have a folder full of icons that I want to turn into unicode symbols in my tooltip.

I know that with resourcepacks this is possible, as seen in this video but I don't want to have users of my mod download and install a resourcepack separately.

I have this JSON file at resources/assets/reignofnether/fonts/resource_icons.json

{
    "providers": [
        {
            "type": "bitmap",
            "file": "reignofnether/textures/icons/items/wheat.png",
            "ascent": 9,
            "height": 9,
            "chars": ["\uE000"]
        },
        {
            "type": "bitmap",
            "file": "reignofnether/textures/icons/items/wood.png",
            "ascent": 9,
            "height": 9,
            "chars": ["\uE001"]
        }
    ]
}

And tried using it with this code:

List<FormattedCharSequence> tooltipLines = List.of(
  List.of(FormattedCharSequence.forward(
    "\uE000 \uE001 test regular text",
    Style.EMPTY.withFont(new ResourceLocation(ReignOfNether.MOD_ID, "textures/fonts/resource_icons.json"))))
)
MC.screen.renderTooltip(poseStack, tooltipLines, mouseX, mouseY, MC.font);

But all I get are invalid characters like this:
kwBCJ3a.png

Posted

You know your mod is already a resource pack? That's how you define other assets like textures and models for your blocks/items.

I also don't think you should be including .json in ResourceLocation path and...

The only place I can see in vanilla that uses Style.withFont() is in EnchantmentNames which references assets/minecraft/font/alt.json using

new ResourceLocation("minecraft", "alt")

 

Beyond that I know very little about what you are trying to do.

Except maybe you want to look at the RegisterClientTooltipComponentFactoriesEvent

which is forge's registration method for things that want to do custom rendering like the vanilla bundle tooltip does - see ClientBundleToolTip and related classes.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted

in case it wasn't clear, I don't think it will load your font unless it is in assets/yourmodid/font/ ?

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

  • 2 weeks later...
Posted (edited)

To anyone who is trying to do this I solved it - the issue was purely bad paths.

I moved my resource_icons.json to assets/<modid>/font/ and changed the file lines to this style:

"file": "reignofnether:icons/items/wheat.png",

The ResourceLocation in my withFont() call is now:

new ResourceLocation(ReignOfNether.MOD_ID, "resource_icons")))

Thanks for the help @warjort, but now do you know how to mix multiple fonts on the same line in a tooltip? When I mix regular text with this unicode mapping on one line the regular text just shows as rectangle (and I really don't want to have to remap all letters and numbers manually in my JSON)
G9nA4Ah.png

EDIT: nevermind, realised I can just copy the vanilla MC's default.json mapping for ASCII characters:

        {
            "type": "bitmap",
            "file": "minecraft:font/ascii.png",
            "ascent": 7,
            "chars": [
                "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000",
                "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000",
                "\u0020\u0021\u0022\u0023\u0024\u0025\u0026\u0027\u0028\u0029\u002a\u002b\u002c\u002d\u002e\u002f",
                "\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037\u0038\u0039\u003a\u003b\u003c\u003d\u003e\u003f",
                "\u0040\u0041\u0042\u0043\u0044\u0045\u0046\u0047\u0048\u0049\u004a\u004b\u004c\u004d\u004e\u004f",
                "\u0050\u0051\u0052\u0053\u0054\u0055\u0056\u0057\u0058\u0059\u005a\u005b\u005c\u005d\u005e\u005f",
                "\u0060\u0061\u0062\u0063\u0064\u0065\u0066\u0067\u0068\u0069\u006a\u006b\u006c\u006d\u006e\u006f",
                "\u0070\u0071\u0072\u0073\u0074\u0075\u0076\u0077\u0078\u0079\u007a\u007b\u007c\u007d\u007e\u0000",
                "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000",
                "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u00a3\u0000\u0000\u0192",
                "\u0000\u0000\u0000\u0000\u0000\u0000\u00aa\u00ba\u0000\u0000\u00ac\u0000\u0000\u0000\u00ab\u00bb",
                "\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510",
                "\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567",
                "\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580",
                "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u2205\u2208\u0000",
                "\u2261\u00b1\u2265\u2264\u2320\u2321\u00f7\u2248\u00b0\u2219\u0000\u221a\u207f\u00b2\u25a0\u0000"
            ]
        },

 

Edited by SoLegendary
solved it

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.