#[Solved] Text is not rendered

22 messages · Page 1 of 1 (latest)

terse orchid
#

When updating the mod from 1.21 to 1.21.8, problems arose with rendering text in the mod's HUD. I think I did everything according to the Fabric documentation. But for some reason it doesn't work.

#
package freedman.saomod.hud;

public class SAOHudBars {


    private static final int BASE_SCREEN_WIDTH = 1920;
    private static final int BASE_SCREEN_HEIGHT = 1080;

    private static final int BASE_WIDTH = 600;
    private static final int BASE_HEIGHT = 95;
    private static float displayedHp = 0;
    private static float displayedMp = 0;
    private static final Identifier CUSTOM_FONT = Identifier.of("saomod", "sao_font");

    public static void register() {
        HudElementRegistry.attachElementBefore(VanillaHudElements.MISC_OVERLAYS,
                Identifier.of("saomod", "hudbars"),
                SAOHudBars::render);
    }

    private static void render(DrawContext context, RenderTickCounter tickDelta) {
        MinecraftClient client = MinecraftClient.getInstance();
        if (client == null || client.player == null || client.options.hudHidden) return;

        int screenWidth = client.getWindow().getFramebufferWidth();
        int screenHeight = client.getWindow().getFramebufferHeight();

        float scaleX = (float) screenWidth / BASE_SCREEN_WIDTH;
        float scaleY = (float) screenHeight / BASE_SCREEN_HEIGHT;

        float autoScale = Math.min(scaleX, scaleY);

        float scaleFix = (float) client.getWindow().getScaleFactor();

        int offsetX = (int) (20 * autoScale);
        int offsetY = (int) (20 * autoScale);

        int nameX = 75;
        int nameY = 8;

        String playerName = client.player.getName().getString();

        Text styledName = Text.literal(playerName).setStyle(Style.EMPTY.withFont(CUSTOM_FONT));


//                context.getMatrices().scale(2.0f, 2.0f);

        context.drawText(client.textRenderer, styledName, nameX, nameY, 0xFFFFFF, false);

ionic root
#

its argb now so change 0xffffff to 0xffffffff

terse orchid
#

What do the last two characters stand for?

terse orchid
#

[Solved] Text is not rendered

ionic root
#

or it may be rgba, either way you were missing the alpha originally

terse orchid
#

I think first number is alpha or opacity. 0 is 100, 5 is 50 percentes.

#

We'll have to play around with this.

ionic root
#

its hexadecimal, ff is 255 and 00 is 0

#

05 would be like 5 or something

terse orchid
#

I'm talking about the zero before x.

ionic root
#

ah

#

that just indicated that youre using hex notation

#

the full 0x bit

terse orchid
#

As someone who is more involved in web development, I am more familiar with a format such as #ffffff.

#

There was a reason to study this more deeply.

ionic root
#

this is the same thing

#

just written slightly differently, and with two extra values for alpha

#

its the same other than # being 0x instead