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.

[1.15.2] How do I blit my own HUD element behind a default minecraft HUD element?

Featured Replies

Posted

I am trying to make the experience bar change color on an event.

My code works, but the expLevel (e.g 30) appears behind my HUD, not infront of it.

 

How would I go about making my HUD appear behind it? Any help would be greatly appreciated!

My code is as follows:

@OnlyIn(Dist.CLIENT)
public class DodgeGui {
	
		private final ResourceLocation bar = new ResourceLocation(Dodge.MODID, "textures/gui/dodgebar.png");
		public final static int width = 182; //182
		private final int height = 5;
		
		public static int j = 0;
	
		@SubscribeEvent
		public void renderOverlay(RenderGameOverlayEvent event) {
			if (event.getType() == RenderGameOverlayEvent.ElementType.TEXT) {
				Minecraft mc = Minecraft.getInstance();
				mc.getTextureManager().bindTexture(bar);
				int scaledHeight = mc.getMainWindow().getScaledHeight() - 32 + 3;
				int scaledWidth = mc.getMainWindow().getScaledWidth() / 2 - 91; //-91
				mc.ingameGUI.blit(scaledWidth, scaledHeight, 0, height, j, height);

	        }
      }			
}

 

Thank you greatly for your time.

- Roman

4 minutes ago, ultra_reemun said:

How would I go about making my HUD appear behind it?

First don't use event.getType() == ElementType.TEXT use ElementType.EXPERIENCE. Then use event.setCanceled(true). Then you will have to render the level and the bar.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author
6 minutes ago, Animefan8888 said:

First don't use event.getType() == ElementType.TEXT use ElementType.EXPERIENCE. Then use event.setCanceled(true). Then you will have to render the level and the bar.

Thank you for your quick reply @Animefan8888! I am trying to keep experience displayed and render my HUD over the top of it as it is a cooldown meter that is only shown temporarily, is there any way I could adapt your code for this?

23 minutes ago, ultra_reemun said:

Thank you for your quick reply @Animefan8888! I am trying to keep experience displayed and render my HUD over the top of it as it is a cooldown meter that is only shown temporarily, is there any way I could adapt your code for this?

Can you show a screenshot of two of what you have/mean? In general you should cancel the original and render your own only when the experience bar shouldn't be rendered to reduce some rendering calls.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • Author
2 minutes ago, Animefan8888 said:

Can you show a screenshot of two of what you have/mean? In general you should cancel the original and render your own only when the experience bar shouldn't be rendered to reduce some rendering calls.

Turns out I wasn't reading your previous answer properly, it worked! Is there anyway I can check to see if the player is in creative mode in order to not render the experience bar? Thank you for all your help :)

9 minutes ago, ultra_reemun said:

Turns out I wasn't reading your previous answer properly, it worked! Is there anyway I can check to see if the player is in creative mode in order to not render the experience bar? Thank you for all your help :)

PlayerEntity::isCreative

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.