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.

Featured Replies

Posted

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

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

 

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.