Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.15.2] Render Overlay blit behaving weirdly (trying to create HUD UI)


Recommended Posts

Hello! I'm trying to adventure myself into minecraft modding, and now my next goal is to render a HUD bar, like a new XP bar for the user.


This is the current code that renders something on screen:


package br.com.rotstudio.phantas.util;

import com.mojang.blaze3d.systems.RenderSystem;

import br.com.rotstudio.phantas.Phantas;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.eventbus.api.SubscribeEvent;

@OnlyIn(value = Dist.CLIENT)
public class RenderGUIHandler{
	Minecraft minecraft = Minecraft.getInstance();
    public ResourceLocation tex;

	public RenderGUIHandler() {
		tex = new ResourceLocation(Phantas.MOD_ID, "textures/hud/hud.png");
	public void renderOverlay(RenderGameOverlayEvent event) {
		if(event.getType() == ElementType.HEALTH) {
			int posY = 16;
	        int posX = 16;
	        RenderSystem.color4f(1F, 1F, 1F, 1F);
	        minecraft.ingameGUI.blit(posX, posY, 0, 0, 32, 32);




But when in game, it renders weirdly:




And the HUD png image looks like this:




It seems its rendering some other minecraft texture atlas on top of my texture, and i have no idea why it does this


does anyone has any clue on what could be happening?


Thank you!

Link to comment
Share on other sites

  1. Do not subscribe to the raw RenderGameOverlayEvent. Choose Pre / Post.
  2. Do not use types other then ALL to add to the HUD, unless you want your elements to also disappear when other mods change e.g. the health display.
  3. After drawing you must re-bind the normal HUD texture (AbstractGui.GUI_ICONS_LOCATION).
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.

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.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.