Posted July 2, 20232 yr 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.