Posted June 8, 20205 yr Hi, I'm attempting to render a text using a custom font, however, its just drawing rectangles. The bitmap image is in src/main/resources/assets/examplemod/textures/font Example ingame: https://imgur.com/a/DjMTVla Current code: private Minecraft mc; private FontRenderer fontRenderer; public ExampleMod() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onClientSetup); MinecraftForge.EVENT_BUS.register(this); } public void onClientSetup(FMLClientSetupEvent event) { mc = Minecraft.getInstance(); fontRenderer = new FontRenderer(mc.textureManager, new Font(mc.textureManager, new ResourceLocation("examplemod", "textures/font/ascii.png"))); } @SubscribeEvent public void onRenderGameOverlay(RenderGameOverlayEvent.Post event) { AbstractGui.fill(5, 5, 30, 30, new Color(255, 0, 255, 5).getRGB()); fontRenderer.drawString("test", 5, 5, new Color(255, 0, 0, 255).getRGB()); } Edited June 9, 20205 yr by LogicalWilly
June 9, 20205 yr Author I've slightly modified my code as I checked the class where minecraft does this natively with its own font, but doesnt seem to work either, same result as before. private Minecraft mc; private FontRenderer fontRenderer; public ExampleMod() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onClientSetup); MinecraftForge.EVENT_BUS.register(this); } public void onClientSetup(FMLClientSetupEvent event) { mc = event.getMinecraftSupplier().get(); } @SubscribeEvent public void onRenderGameOverlay(RenderGameOverlayEvent.Post event) { if(fontRenderer == null) { //Temporarily define it here for testing, as I get a the error Exception caught during firing event: Rendersystem called from wrong thread on the onClientSetup fontRenderer = mc.getFontResourceManager().getFontRenderer(new ResourceLocation("examplemod", "textures/font/ascii.png")); } AbstractGui.fill(5, 5, 30, 30, new Color(255, 0, 255, 5).getRGB()); fontRenderer.drawString("test", 5, 5, new Color(255, 0, 0, 255).getRGB()); }
June 9, 20205 yr Author Solved, anyone who has the same problem can use this git as an example. https://github.com/Vazkii/Patchouli
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.