Jump to content

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


ultra_reemun

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.