Jump to content

Recommended Posts

Posted (edited)

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 by LogicalWilly
Posted

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());
	}

 

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.