Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

About the problem I'm having when trying to convert a FormattedCharSequence to a String.

Featured Replies

Posted

I override the drawInBatch method in my custom font renderer, and then I use the following code to return the font instance.

    @Override
    public void initializeClient(Consumer<IClientItemExtensions> consumer) {
        consumer.accept(new IClientItemExtensions() {
            @Override
            public @NotNull Font getFont(ItemStack stack, FontContext context) {
                return SuperFont.INSTANCE;
            }
        });
    }

My code is as follows.
 

public class SuperFont extends Font {
    private float tick = 0.0f;

    public SuperFont(Function<ResourceLocation, FontSet> p_243253_, boolean p_243245_) {
        super(p_243253_, p_243245_);
        MinecraftForge.EVENT_BUS.register(this);
    }

    @SubscribeEvent
    public void tick(TickEvent.ClientTickEvent evt) {
        if (evt.phase == TickEvent.Phase.START) {
            this.tick += 1.0f;
            if (this.tick >= 720.0f) {
                this.tick = 0.0f;
            }
        }
    }
      
    @Override
    public int drawInBatch(@NotNull FormattedCharSequence formattedCharSequence, float x, float y, int color, boolean boolean1, @NotNull 	   Matrix4f matrix4f, @NotNull MultiBufferSource multiBufferSource, boolean boolean2, int int1, int int2) {
        float the_step = 0.0f;
        String text = formattedCharSequence.toString();
        text = text.replaceAll("§[0-9a-fA-Fklmnor]", "");
        char[] array_char = text.toCharArray();
        for (char c : array_char) {
            String s = String.valueOf(c);
            int tc = Color.HSBtoRGB(this.nextColorHue(the_step) / 100.0f, 0.8f, 0.8f);
            super.drawInBatch(s, x, y, tc, boolean1, matrix4f, multiBufferSource, boolean2, int1, int2);
            x += (float) this.width(String.valueOf(c));
            the_step += 1.0f;
        }
        return (int)x;
    }
      
    public float nextColorHue(float the_step) {
        float tick = (this.tick + the_step) % 720.0f;
        if (tick >= 360.0f) {
            return 720.0f - tick;
        }
        return tick;
    }
      
    public static final SuperFont INSTANCE = new SuperFont(Minecraft.getInstance().fontManager.createFont().fonts, true);
}

I also used Access Transformer.
 

public-f net.minecraft.client.Minecraft f_91045_ # fontManager

But I get it in the game.

https://upload.cc/i1/2023/07/02/LDePEB.png
I checked many posts and questions, as well as official documentation, but I couldn't find a class or method that can convert types.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.