Jump to content

(UNSOLVED) [1.7.10/1.8] Help replacing the in-game HUD?


Ms_Raven

Recommended Posts

I want to replace the health/hunger/oxygen/armour/xp/jump bars with my own.

 

But I can't figure out how to cancel only those specific render types.

 

I try to check if it's rendering those types, load mine then cancel the event but nothing renders. Not mine, not the ones I want cancelled, not even the crosshair, inventory or pause menu.

 

How do I do this right?

 

public class HeadsUpDisplay extends Gui
{

private Minecraft mc;
private static final ResourceLocation texturepath = new ResourceLocation(This.MODID, "hud.png");
protected static final RenderItem itemRenderer = new RenderItem();

public HeadsUpDisplay()
{
	super();
	this.mc = Minecraft.getMinecraft();
}

@SubscribeEvent
public void renderHUD(RenderGameOverlayEvent.Pre event)
{
	if (event.isCancelable() || event.type == ElementType.HEALTH || event.type == ElementType.FOOD
			|| event.type == ElementType.AIR || event.type == ElementType.HOTBAR || event.type == ElementType.EXPERIENCE
			|| event.type == ElementType.JUMPBAR)
	{
		render();
		event.setCanceled(true);
	}

}

private void render()
{

	EntityPlayer player = mc.thePlayer;
	FontRenderer fontrenderer = this.mc.fontRenderer;
	InventoryPlayer inventoryplayer = this.mc.thePlayer.inventory;

	int xPos = (mc.displayWidth / 2) - 90;
	int yPos = mc.displayHeight - 60;

	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	GL11.glDisable(GL11.GL_LIGHTING);
	GL11.glEnable(GL11.GL_BLEND);

	this.mc.getTextureManager().bindTexture(texturepath);

	// Render main HUD background
	this.drawTexturedModalRect(xPos, yPos, 0, 0, 180, 54);

	// Render health
	int health = (int) (player.getHealth() * 2);
	int maxHealth = (int) (player.getMaxHealth() * 2);

	int healthWidth = (health / maxHealth) * 71;

	this.drawTexturedModalRect(xPos + 4, yPos + 21, 0, 185, healthWidth, 9);

	if (health <= 1)
	{
		this.drawTexturedModalRect(xPos + 66, yPos + 13, 4, 57, 4, 10);
	}
	String hp = health + "/" + maxHealth;
	int w1 = fontrenderer.getStringWidth(hp) / 2;
	fontrenderer.drawStringWithShadow(hp, xPos + 122, yPos + 13, 0x000000);

	// Render hunger
	int hunger = player.getFoodStats().getFoodLevel();

	int hungerWidth = (hunger / 20) * 71;

	this.drawTexturedModalRect(xPos + 105, yPos + 21, 9, 185, hungerWidth, 9);

	if (hunger <= 1)
	{
		this.drawTexturedModalRect(xPos + 110, yPos + 13, 0, 57, 4, 10);
	}

	String hDisplay = hunger + "/" + 20;
	int w2 = fontrenderer.getStringWidth(hDisplay) / 2;
	fontrenderer.drawStringWithShadow(hDisplay, xPos + 56, yPos + 13, 0x000000);

	// Render hotbar item selector
	this.drawTexturedModalRect(xPos + 6 + inventoryplayer.currentItem * 20, yPos - 34, 8, 57, 8, 7);

	// Render hotbar icons
	this.mc.mcProfiler.startSection("actionBar");
	GL11.glEnable(GL12.GL_RESCALE_NORMAL);
	RenderHelper.enableGUIStandardItemLighting();

	for (int i = 0; i < 9; ++i)
	{
		this.renderInventorySlot(i, xPos + i * 20, yPos + 37, 1);
	}

	RenderHelper.disableStandardItemLighting();
	GL11.glDisable(GL12.GL_RESCALE_NORMAL);
	this.mc.mcProfiler.endSection();
	GL11.glDisable(GL11.GL_BLEND);

	// Render horse jump bar
	if (this.mc.thePlayer.isRidingHorse())
	{
		this.mc.mcProfiler.startSection("jumpBar");
		float jump = this.mc.thePlayer.getHorseJumpPower();
		int jumpMax = 148;

		this.drawTexturedModalRect(xPos + 16, yPos - 19, 0, 90, (int) ((jump / jumpMax) * jumpMax), 19);

		if (jump > 0)
		{
			this.drawTexturedModalRect(xPos + 20, yPos + 8, 0, 109, 140, 4);
		}

		this.mc.mcProfiler.endSection();
	}

	// Render xp bar
	int xp = (int) player.experience;
	int toNextLevel = player.xpBarCap();
	int level = player.experienceLevel;

	String s = "" + level;
	int w3 = fontrenderer.getStringWidth(s) / 2;
	fontrenderer.drawStringWithShadow(s, xPos + 90, yPos + 20, 0x000000);

	if (level > 0)
	{
		this.drawTexturedModalRect(xPos + 20, yPos + 4, 20, 57, (xp / toNextLevel) * 140, 4);
	}

	// Render armour
	// Render oxygen

}

protected void renderInventorySlot(int slot, int x, int y, float tick)
{
	ItemStack itemstack = this.mc.thePlayer.inventory.mainInventory[slot];

	if (itemstack != null)
	{
		float f1 = (float) itemstack.animationsToGo - tick;

		if (f1 > 0.0F)
		{
			GL11.glPushMatrix();
			float f2 = 1.0F + f1 / 5.0F;
			GL11.glTranslatef((float) (x + , (float) (y + 12), 0.0F);
			GL11.glScalef(1.0F / f2, (f2 + 1.0F) / 2.0F, 1.0F);
			GL11.glTranslatef((float) (-(x + ), (float) (-(y + 12)), 0.0F);
		}

		itemRenderer.renderItemAndEffectIntoGUI(this.mc.fontRenderer, this.mc.getTextureManager(), itemstack, x, y);

		if (f1 > 0.0F)
		{
			GL11.glPopMatrix();
		}

		itemRenderer.renderItemOverlayIntoGUI(this.mc.fontRenderer, this.mc.getTextureManager(), itemstack, x, y);
	}
}
}

Link to comment
Share on other sites

RenderGameOverlayEvent#isCancable()

wil always return true, so you will always cancel rendering for everything.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Okay that was dumb.

 

But now after fixing that my HUD still won't render.

 

	@SubscribeEvent
public void renderHUD(RenderGameOverlayEvent.Pre event)
{
	if (event.isCancelable())
	{
		if (event.type == ElementType.HEALTH || event.type == ElementType.FOOD || event.type == ElementType.AIR
				|| event.type == ElementType.HOTBAR || event.type == ElementType.EXPERIENCE
				|| event.type == ElementType.JUMPBAR)
		{
			render();
			event.setCanceled(true);
		}
	}
}

 

If the event is cancelled after it renders or if I don't cancel it at all, it just shows a really glitchy-looking black-and-white version of the vanilla HUD.

 

kimf9cv.png

 

If the event is cancelled before it renders, the vanilla HUD doesn't render but mine still doesn't either.

 

Link to comment
Share on other sites

Hey so what I have found is that the rendering needs to be cancelled in a specific order and reimplemented in a specific order. In order to cancel Hunger, Health, Exp, and the storage...

 

@SubscribeEvent(priority=EventPriority.NORMAL)
public void onRenderPre(RenderGameOverlayEvent.Pre event) {

	if (event.type == ElementType.HOTBAR) {
		event.setCanceled(true);
		return;
	}

	if (event.type == ElementType.FOOD) {
		event.setCanceled(true);
		return;
	}
	if (event.type == ElementType.EXPERIENCE) {
		event.setCanceled(true);
		return;
	}

	if (event.type == ElementType.HEALTH) {
		event.setCanceled(true);
		return;
	}

   ///Im not positive if you need this statement but I kept it in otherwise I noticed weird glitches with my custom stuff
	if (event.type != ElementType.FOOD) {
			return;
	}
}

 

then in the RenderGameOverlay Post event render your new custom elements in the same order as above. Note, I am unsure where the air bar fits in I havent messed with it yet, lemme know if you figure that out. If you mess up the order you get weird glitches I found where some of your custom stuff will look weird. Im not sure why this happens but this seems to work perfectly for me.

 

@SubscribeEvent(priority=EventPriority.NORMAL)
public void RenderBattleGUI(RenderGameOverlayEvent.Post event) {

	if (event.type != ElementType.CROSSHAIRS) {
		return;
	}

	////////////////Render Custom Hot Bar////////////////////////////////////////////	


	////////////////Render Custom Food Bar////////////////////////////////////////////


	///////////////////Render Custom ExpBar////////////////////////////////////////////


	////////////////Render Custom HealthBar////////////////////////////////////////////

}

 

Also ---------------> Hit Thanks if you dont mind :)

Link to comment
Share on other sites

I render my custom gui hud elements as so in the event you see above

 

                GL11.glEnable(GL11.GL_BLEND);
	GL11.glDisable(GL11.GL_DEPTH_TEST);
	GL11.glDepthMask(false);
	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	GL11.glDisable(GL11.GL_ALPHA_TEST);

                        ...//Custom Stuff...

                  ///Then the stuff you care about///

                 /////////ExpBar////////////////////////////////////////////
	this.mc.getTextureManager().bindTexture(expBarTexture);
	int expBarWidth = (int)(((float) (((int)expGained) -this.getExpFromLevel(id, level))/ (this.getExpFromLevel(id, level + 1)-this.getExpFromLevel(id, level))) * pixelWidthOfTexture);
	drawTexturedModalRect(width/2 -106, height- 32, 0, 0, 77, 9);
	drawTexturedModalRect(width/2 -106 + 2, height- 32 + 1, 0, 9, expBarWidth, 5);

	////////////////HealthBar////////////////////////////////////////////
	this.mc.getTextureManager().bindTexture(healthBarTexture);
	int healthBarWidth = (int)(((float) (int)this.mc.thePlayer.getHealth() / hpMax) * pixelWidthOfTexture);
	drawTexturedModalRect(width/2 -106, height- 40, 0, 0, 77, 9);
	drawTexturedModalRect(width/2 -106 + 2, height- 40 + 1, 0, 19, healthBarWidth, 5);
               
                  ...//.etc etc....

                  ///more custom stuff///

                GL11.glDisable(GL11.GL_BLEND);
	GL11.glEnable(GL11.GL_DEPTH_TEST);
	GL11.glDepthMask(true);

 

Again The Thank you btn is ---> that a way ish :)

Link to comment
Share on other sites

Unfortunately that still doesn't work. Nothing renders.

 

@SubscribeEvent
public void clear(RenderGameOverlayEvent.Pre event)
{
	if (event.type == ElementType.HOTBAR)
	{
		event.setCanceled(true);
		return;
	}

	if (event.type == ElementType.FOOD)
	{
		event.setCanceled(true);
		return;
	}
	if (event.type == ElementType.EXPERIENCE)
	{
		event.setCanceled(true);
		return;
	}

	if (event.type == ElementType.HEALTH)
	{
		event.setCanceled(true);
		return;
	}
	if (event.type == ElementType.JUMPBAR)
	{
		event.setCanceled(true);
		return;
	}
	if (event.type == ElementType.AIR)
	{
		event.setCanceled(true);
		return;
	}
	if (event.type == ElementType.ARMOR)
	{
		event.setCanceled(true);
		return;
	}

	if (event.type != ElementType.FOOD)
	{
		return;
	}
}

@SubscribeEvent
public void render(RenderGameOverlayEvent.Post event)
{
	EntityPlayer player = mc.thePlayer;
	FontRenderer fontrenderer = this.mc.fontRenderer;
	InventoryPlayer inventoryplayer = this.mc.thePlayer.inventory;

	this.mc.getTextureManager().bindTexture(texturepath);

	int xPos = (mc.displayWidth / 2) - 90;
	int yPos = mc.displayHeight - 60;

	GL11.glEnable(GL11.GL_BLEND);
	GL11.glDisable(GL11.GL_DEPTH_TEST);
	GL11.glDepthMask(false);
	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	GL11.glDisable(GL11.GL_ALPHA_TEST);

	// HOTBAR - ICONS
	this.mc.mcProfiler.startSection("actionBar");
	GL11.glEnable(GL12.GL_RESCALE_NORMAL);
	RenderHelper.enableGUIStandardItemLighting();

	for (int i = 0; i < 9; ++i)
	{
		this.renderInventorySlot(i, xPos + i * 20, yPos + 37, 1);
	}

	RenderHelper.disableStandardItemLighting();
	GL11.glDisable(GL12.GL_RESCALE_NORMAL);
	this.mc.mcProfiler.endSection();
	GL11.glDisable(GL11.GL_BLEND);

	// HOTBAR - SELECTOR
	this.drawTexturedModalRect(xPos + 6 + inventoryplayer.currentItem * 20, yPos - 34, 8, 57, 8, 7);

	if (!mc.thePlayer.capabilities.isCreativeMode)
	{
		// HUD BACKGROUND
		this.drawTexturedModalRect(xPos, yPos, 0, 0, 180, 54);

		// FOOD BAR
		int hunger = player.getFoodStats().getFoodLevel();

		int hungerWidth = (hunger / 20) * 71;

		this.drawTexturedModalRect(xPos + 105, yPos + 21, 9, 185, hungerWidth, 9);

		if (hunger <= 1)
		{
			this.drawTexturedModalRect(xPos + 110, yPos + 13, 0, 57, 4, 10);
		}

		String hDisplay = hunger + "/" + 20;
		int w2 = fontrenderer.getStringWidth(hDisplay) / 2;
		fontrenderer.drawStringWithShadow(hDisplay, xPos + 56, yPos + 13, 0x000000);

		// EXPERIENCE BAR
		int xp = (int) player.experience;
		int toNextLevel = player.xpBarCap();
		int level = player.experienceLevel;

		String s = "" + level;
		int w3 = fontrenderer.getStringWidth(s) / 2;
		fontrenderer.drawStringWithShadow(s, xPos + 90, yPos + 20, 0x000000);

		if (level > 0)
		{
			this.drawTexturedModalRect(xPos + 20, yPos + 4, 20, 57, (xp / toNextLevel) * 140, 4);
		}

		// HEALTH BAR
		int health = (int) (player.getHealth() * 2);
		int maxHealth = (int) (player.getMaxHealth() * 2);

		int healthWidth = (health / maxHealth) * 71;

		this.drawTexturedModalRect(xPos + 4, yPos + 21, 0, 185, healthWidth, 9);

		if (health <= 1)
		{
			this.drawTexturedModalRect(xPos + 66, yPos + 13, 4, 57, 4, 10);
		}
		String hp = health + "/" + maxHealth;
		int w1 = fontrenderer.getStringWidth(hp) / 2;
		fontrenderer.drawStringWithShadow(hp, xPos + 122, yPos + 13, 0x000000);

		// HORSE BAR
		if (this.mc.thePlayer.isRidingHorse())
		{
			this.mc.mcProfiler.startSection("jumpBar");
			float jump = this.mc.thePlayer.getHorseJumpPower();
			int jumpMax = 148;

			this.drawTexturedModalRect(xPos + 16, yPos - 19, 0, 90, (int) ((jump / jumpMax) * jumpMax), 19);

			if (jump > 0)
			{
				this.drawTexturedModalRect(xPos + 20, yPos + 8, 0, 109, 140, 4);
			}

			this.mc.mcProfiler.endSection();
		}

		// OXYGEN
		// ARMOUR
	}
}

Link to comment
Share on other sites

Uh, if it wasn't being registered then nothing would happen. As I've said several times, nothing renders, not mine or the vanilla.

So the pre-event is clearly being called. The post-event that's supposed to render mine is being called, for some reason it's not doing anything.

Link to comment
Share on other sites

Please understand that the event is posted for each element type, with different rendering state.

If you cancel the event with element type == ALL, NOTHING is rendered.

You can cancel any number of them, but you need to choose ONE element type to render ONCE.

See GuiInGameForge to check the rendering states.

Link to comment
Share on other sites

This isn't hard at all just remember:

 

1.) You should cancel this event in Pre

 

2) Cancelling "ElementType.ALL" will disable every HUD rendered element

 

Take a look at this example:

 

public void onEvent(RenderGameOverlayEvent.Pre event)
{
    switch(event.type)
    {
        case HOTBAR : event.setCanceled(event.isCancelable); break;
        case ANOTHERELEMENT : yourRenderMethod(); event.setCanceled(event.isCancelable); break;
        default : break;
    }
}

 

EDIT: Depending on your rendering you should probably render your new widgets / icons in current / post. You can also decide when to render it based on when other elements render, shown below:

 

public void onEvent(RenderGameOverlayEvent event)
{
    if(event.type.equals(ElementType.EXPERIENCE)
    {
        yourRenderMethodOnExperienceBar();
    }
}

Development of Plugins [2012 - 2014] Development of Mods [2012 - Current]

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://pastebin.com/VwpAW6PX My game crashes upon launch when trying to implement the Oculus mod to this mod compilation, above is the crash report, I do not know where to begin to attempt to fix this issue and require assistance.
    • https://youtube.com/shorts/gqLTSMymgUg?si=5QOeSvA4TTs-bL46
    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server. Giving options for players if they want to spend real money or grind to obtain exclusive packages. - Black Market: A hidden store for trading that operates outside our traditional stores, like custom enchantments, exclusive items and more. Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. 📈 Skills: RPG-style skill system that enhances your gaming experience! 🎮 Leaderboards: Compete and shine! Top players are rewarded weekly! 🏆 Random Teleporter: Travel instantly across different worlds with a click! 🌐 Custom World Generation: Beautifully generated world. 🌍 Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. 🏰 Kits: Unlock ranks and gain access to various kits. 🛠️ Fishing Tournament: Compete in a friendly fishing tournament! 🎣 Chat Games: Enjoy games right within the chat! 🎲 Minions: Get some help from your loyal minions. 👥 Piñata Party: Enjoy a festive party with Piñatas! 🎉 Quests: Over 1000 quests that you can complete! 📜 Bounty Hunter: Set a bounty on a player's head. 💰 Tags: Displayed on nametags, in the tab list, and in chat. 🏷️ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! 🟢 Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. 🔲✨[ Player Warp: Set your own warp points for other players to teleport to. 🌟 Display Shop: Create your own shop and sell to other players! 🛒 Item Skins: Customize your items with unique skins. 🎨 Pets: Your cute loyal companion to follow you wherever you go! 🐾 Cosmetics: Enhance the look of your character with beautiful cosmetics! 💄 XP-Bottle: Store your exp safely in a bottle for later use! 🍶 Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! 📦 Glowing: Stand out from other players with a colorful glow! ✨ Player Particles: Over 100 unique particle effects to show off. 🎇 Portable Inventories: Over virtual inventories with ease. 🧳 And a lot more! Become part of our growing community today! Discord: https://cubehaven.net/discord Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132
    • # Problematic frame: # C [libopenal.so+0x9fb4d] It is always the same issue - this refers to the Linux OS - so your system may prevent Java from working   I am not familiar with Linux - check for similar/related issues  
  • Topics

×
×
  • Create New...

Important Information

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