Jump to content

How would you go about replacing the HealthBar with a custom one?


R3DActual

Recommended Posts

So, here's the code I have to show the health bar currently without replacing it. How would I go about replacing the default health bar?

public class HealthRenderer extends Gui{
	public static HealthRenderer instance = new HealthRenderer();
	
	private final ResourceLocation bar = new ResourceLocation(Reference.MODID, "textures/gui/hpbar.png");
    private final int tex_width = 102, tex_height = 8, bar_width = 100, bar_height = 6;

    @SubscribeEvent
    public void renderOverlay(RenderGameOverlayEvent e) {
        Minecraft mc = Minecraft.getMinecraft();
		EntityPlayer entity = mc.thePlayer;
		FontRenderer fontObj = mc.fontRendererObj;
		
        if (e.type == RenderGameOverlayEvent.ElementType.TEXT) {
            mc.renderEngine.bindTexture(bar);
            float oneUnit = (float)bar_width / entity.getMaxHealth();
            int currentWidth = (int)(oneUnit * entity.getHealth());
            float health = entity.getHealth();
			//String pHealth = String.format("%.1f", health);
			//drawString(fontObj, pHealth, 30, 5, -1);
			
            drawTexturedModalRect(0, 0, 0, 0, tex_width, tex_height);
            drawTexturedModalRect(1, 0, 1, tex_height, currentWidth, tex_height);
        }
    }
}

Also, here's the image I'm using
t02gNgB.png

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.



×
×
  • Create New...

Important Information

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