Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm trying to add a new hud element that represents data in a players capability. That works fine, but existing HUD elements break with my additions.

At first, the health bar, hunger bar and exp bar where screwed

2019-01-28_21_47_15.thumb.png.fcdbacea7f82fdc98607b2e015dad907.png

 

Source Code

But after adding .post to all the events i managed to fix it somewhat. But now i'm stuck. It's just the hunger bar which is broken now. I tried adding m.renderEngine.bindTexture(Gui.ICONS) but it didn't fix it.

2019-01-29_00_19_34.thumb.png.0836bf115436b4e4e61596e2c30db63b.png 

Source Code

package com.javisel.gui.bar.mana;

import com.google.common.graph.ElementOrder.Type;
import com.javisel.main.References;
import com.javisel.main.Utilities;
import com.javisel.resourcesystems.EnergyProvider;
import com.javisel.resourcesystems.ManaProvider;
import com.javisel.resourcesystems.Resources;
import com.javisel.resourcesystems.SoulsProvider;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent;

public class AOGGUI extends Gui {

	private final ResourceLocation mana = new ResourceLocation(References.MODID, "textures/gui/manabar.png");
	private final ResourceLocation energy = new ResourceLocation(References.MODID, "textures/gui/energybar.png");
	private final ResourceLocation soul = new ResourceLocation(References.MODID, "textures/gui/soulcounter.png");
	private final int tex_width = 100, tex_height = 10, barwidth = 98, barheight = 8, soulcounterwidth = 30,
			soulcounterheight = 30;
	int ticks = 0;
	private Resources usingResource = Resources.MANA;

	@SubscribeEvent(priority = EventPriority.NORMAL)
	public void RenderManaBar(RenderGameOverlayEvent.Post e) {
		Minecraft m = Minecraft.getMinecraft();

		if (e.getType() == ElementType.TEXT) {

			float manaratio = m.player.getCapability(ManaProvider.Mana_CAP, null).getmana()
					/ m.player.getCapability(ManaProvider.Mana_CAP, null).getmaxmana();
			int currentWidth = (int) (barwidth * manaratio);
			if (Utilities.displayingresource(m.player) == Resources.MANA) {
				usingResource = Resources.MANA;

				m.renderEngine.bindTexture(mana);
				drawTexturedModalRect(0, 0, 0, 0, tex_width, tex_height);
				drawTexturedModalRect(1, 0, 1, tex_height, currentWidth, tex_height);
				drawCenteredString(m.fontRenderer,
						Math.round(m.player.getCapability(ManaProvider.Mana_CAP, null).getmana()) + "/"
								+ Math.round(m.player.getCapability(ManaProvider.Mana_CAP, null).getmaxmana()),
						tex_width / 2, 1, Integer.parseInt("ffffff", 16));
				m.renderEngine.bindTexture(Gui.ICONS);
			}
		}

	}

	@SubscribeEvent(priority = EventPriority.NORMAL)
	public void RenderEnergyBar(RenderGameOverlayEvent.Post e) {
		Minecraft m = Minecraft.getMinecraft();

		if (e.getType() == ElementType.TEXT) {

			float energyratio = m.player.getCapability(EnergyProvider.Energy_CAP, null).getEnergy()
					/ m.player.getCapability(EnergyProvider.Energy_CAP, null).getmaxEnergy();
			int currentWidth = (int) (barwidth * energyratio);
			if (Utilities.displayingresource(m.player) == Resources.ENERGY) {
				usingResource = Resources.ENERGY;
				m.renderEngine.bindTexture(energy);
				drawTexturedModalRect(0, 0, 0, 0, tex_width, tex_height);
				drawTexturedModalRect(1, 0, 1, tex_height, currentWidth, tex_height);
				drawCenteredString(m.fontRenderer,
						Math.round(m.player.getCapability(EnergyProvider.Energy_CAP, null).getEnergy()) + "/"
								+ Math.round(m.player.getCapability(EnergyProvider.Energy_CAP, null).getmaxEnergy()),
						tex_width / 2, 1, Integer.parseInt("ffffff", 16));
				m.renderEngine.bindTexture(Gui.ICONS);
			}
		}

	}

	@SubscribeEvent(priority = EventPriority.NORMAL)
	public void RenderSoulCounter(RenderGameOverlayEvent.Post e) {
		Minecraft m = Minecraft.getMinecraft();

		m.renderEngine.bindTexture(soul);
		if (e.getType() == ElementType.TEXT) {

			drawTexturedModalRect(0, tex_height + 1, 0, 0, soulcounterwidth, soulcounterheight);
			drawCenteredString(m.fontRenderer,
					Integer.toString(Math.round(m.player.getCapability(SoulsProvider.Souls_CAP, null).getSouls())),
					soulcounterwidth / 2, soulcounterheight + 1, Integer.parseInt("ffffff", 16));

			m.renderEngine.bindTexture(Gui.ICONS);
		}
	}

	@SubscribeEvent(priority = EventPriority.NORMAL)
	public void RenderSoulCounterText(RenderGameOverlayEvent.Post e) {
		Minecraft m = Minecraft.getMinecraft();

		m.renderEngine.bindTexture(soul);
		if (e.getType() == ElementType.TEXT) {

			drawCenteredString(m.fontRenderer,
					Integer.toString(Math.round(m.player.getCapability(SoulsProvider.Souls_CAP, null).getSouls())),
					soulcounterwidth / 2, soulcounterheight + 1, Integer.parseInt("ffffff", 16));

			m.renderEngine.bindTexture(Gui.ICONS);
		}
	}

}

Any idea as to what's going wrong? 

You need to rebind the textures that Minecraft expects to be in place, they can be found at GuiInGame and/or GuiInGameForge

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.