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

    • OLXTOTO: Platform Maxwin dan Gacor Terbesar Sepanjang Masa OLXTOTO telah menetapkan standar baru dalam dunia perjudian dengan menjadi platform terbesar untuk pengalaman gaming yang penuh kemenangan dan kegacoran, sepanjang masa. Dengan fokus yang kuat pada menyediakan permainan yang menghadirkan kesenangan tanpa batas dan peluang kemenangan besar, OLXTOTO telah menjadi pilihan utama bagi para pencinta judi berani di Indonesia. Maxwin: Mengejar Kemenangan Terbesar Maxwin bukan sekadar kata-kata kosong di OLXTOTO. Ini adalah konsep yang ditanamkan dalam setiap aspek permainan yang mereka tawarkan. Dari permainan slot yang menghadirkan jackpot besar hingga berbagai opsi permainan togel dengan hadiah fantastis, para pemain dapat memperoleh peluang nyata untuk mencapai kemenangan terbesar dalam setiap taruhan yang mereka lakukan. OLXTOTO tidak hanya menawarkan kesempatan untuk menang, tetapi juga menjadi wadah bagi para pemain untuk meraih impian mereka dalam perjudian yang berani. Gacor: Keberuntungan yang Tak Tertandingi Keberuntungan seringkali menjadi faktor penting dalam perjudian, dan OLXTOTO memahami betul akan hal ini. Dengan berbagai strategi dan analisis yang disediakan, pemain dapat menemukan peluang gacor yang tidak tertandingi dalam setiap taruhan. Dari hasil togel yang tepat hingga putaran slot yang menguntungkan, OLXTOTO memastikan bahwa setiap taruhan memiliki potensi untuk menjadi momen yang mengubah hidup. Inovasi dan Kualitas Tanpa Batas Tidak puas dengan prestasi masa lalu, OLXTOTO terus berinovasi untuk memberikan pengalaman gaming terbaik kepada para pengguna. Dengan menggabungkan teknologi terbaru dengan desain yang ramah pengguna, platform ini menyajikan antarmuka yang mudah digunakan tanpa mengorbankan kualitas. Setiap pembaruan dan peningkatan dilakukan dengan tujuan tunggal: memberikan pengalaman gaming yang tanpa kompromi kepada setiap pengguna. Komitmen Terhadap Kepuasan Pelanggan Di balik kesuksesan OLXTOTO adalah komitmen mereka terhadap kepuasan pelanggan. Tim dukungan pelanggan yang profesional siap membantu para pemain dalam setiap langkah perjalanan gaming mereka. Dari pertanyaan teknis hingga bantuan dengan transaksi keuangan, OLXTOTO selalu siap memberikan pelayanan terbaik kepada para pengguna mereka. Penutup: Mengukir Sejarah dalam Dunia Perjudian Daring OLXTOTO bukan sekadar platform perjudian berani biasa. Ini adalah ikon dalam dunia perjudian daring Indonesia, sebuah destinasi yang menyatukan kemenangan dan keberuntungan dalam satu tempat yang mengasyikkan. Dengan komitmen mereka terhadap kualitas, inovasi, dan kepuasan pelanggan, OLXTOTO terus mengukir sejarah dalam perjudian dunia berani, menjadi nama yang tak terpisahkan dari pengalaman gaming terbaik. Bersiaplah untuk mengalami sensasi kemenangan terbesar dan keberuntungan tak terduga di OLXTOTO - platform maxwin dan gacor terbesar sepanjang masa.
    • OLXTOTO - Bandar Togel Online Dan Slot Terbesar Di Indonesia OLXTOTO telah lama dikenal sebagai salah satu bandar online terkemuka di Indonesia, terutama dalam pasar togel dan slot. Dengan reputasi yang solid dan pengalaman bertahun-tahun, OLXTOTO menawarkan platform yang aman dan andal bagi para penggemar perjudian daring. DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI Beragam Permainan Togel Sebagai bandar online terbesar di Indonesia, OLXTOTO menawarkan berbagai macam permainan togel. Mulai dari togel Singapura, togel Hongkong, hingga togel Sidney, pemain memiliki banyak pilihan untuk mencoba keberuntungan mereka. Dengan sistem yang transparan dan hasil yang adil, OLXTOTO memastikan bahwa setiap taruhan diproses dengan cepat dan tanpa keadaan. Slot Online Berkualitas Selain togel, OLXTOTO juga menawarkan berbagai permainan slot online yang menarik. Dari slot klasik hingga slot video modern, pemain dapat menemukan berbagai opsi permainan yang sesuai dengan preferensi mereka. Dengan grafis yang memukau dan fitur bonus yang menggiurkan, pengalaman bermain slot di OLXTOTO tidak akan pernah membosankan. Keamanan dan Kepuasan Pelanggan Terjamin Keamanan dan kepuasan pelanggan merupakan prioritas utama di OLXTOTO. Mereka menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan para pemain. Tim dukungan pelanggan yang ramah dan responsif siap membantu pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Promosi dan Bonus Menarik OLXTOTO sering menawarkan promosi dan bonus menarik kepada para pemainnya. Mulai dari bonus selamat datang hingga bonus deposit, pemain memiliki kesempatan untuk meningkatkan kemenangan mereka dengan memanfaatkan berbagai penawaran yang tersedia. Penutup Dengan reputasi yang solid, beragam permainan berkualitas, dan komitmen terhadap keamanan dan kepuasan pelanggan, OLXTOTO tetap menjadi salah satu pilihan utama bagi para pecinta judi online di Indonesia. Jika Anda mencari pengalaman berjudi yang menyenangkan dan terpercaya, OLXTOTO layak dipertimbangkan.
    • I have been having a problem with minecraft forge. Any version. Everytime I try to launch it it always comes back with error code 1. I have tried launching from curseforge, from the minecraft launcher. I have also tried resetting my computer to see if that would help. It works on my other computer but that one is too old to run it properly. I have tried with and without mods aswell. Fabric works, optifine works, and MultiMC works aswell but i want to use forge. If you can help with this issue please DM on discord my # is Haole_Dawg#6676
    • Add the latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • I have no idea how a UI mod crashed a whole world but HUGE props to you man, just saved me +2 months of progress!  
  • Topics

×
×
  • Create New...

Important Information

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