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

Currently I have my own overlays or added overlays, I'm slowly replacing the existing HEALTH and FOOD overlays with my own Health and Stamina models and then adding Mana later on.

But in my works I've noticed the XP bar has vanished however the XP counter (1, 2, 3 etc) that number still appears if you collect enough xp but the progress bar is not visible 

 

package htd.rot.events.client;

import htd.rot.Rot;
import htd.rot.capability.playerextra.CapPlayerExtra;
import htd.rot.capability.playerextra.CapPlayerExtraData;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
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;

public class EventPlayerOverlayGui extends Gui
{
	// Registered in ClientProxy
	private Minecraft mc;
	private static final ResourceLocation staminaTexture = new ResourceLocation(Rot.MODID + ":textures/gui/stam_bar.png");

	private int barW = 81, barH = 9;
	private int innerBarW = barW - 2;

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

	@SubscribeEvent(priority = EventPriority.NORMAL)
	public void onRenderExperienceBar(RenderGameOverlayEvent event)
	{
		if (event.getType() == ElementType.FOOD)
		{
			event.setCanceled(true);
			return;
		}
		if (event.getType() != ElementType.EXPERIENCE)
		{
			return;
		}

		ScaledResolution res = event.getResolution();
		int bottomScreen = res.getScaledHeight(), halfHeight = bottomScreen / 2;
		int rightScreen = res.getScaledWidth(), halfWidth = rightScreen / 2;
		CapPlayerExtraData capPlayerExtra = Minecraft.getMinecraft().thePlayer.getCapability(CapPlayerExtra.CAPABILITY, null);

		int currentbarwidth = 0;
		int xPos = halfWidth + 10;
		int yPos = bottomScreen - 22 - ((this.barH * 2) - 1);

		// Draw Stam Bar
		this.mc.getTextureManager().bindTexture(staminaTexture);

		float currentStam = capPlayerExtra.getCurrentStam();
		float maxStam = capPlayerExtra.MAX_STAM;

		currentbarwidth = MathHelper.clamp_int((int) ((currentStam / maxStam) * this.innerBarW), 0, this.innerBarW);

		drawTexturedModalRect(xPos, yPos, 0, 0, this.barW, this.barH);
		drawTexturedModalRect(xPos + 1, yPos, 0, this.barH, currentbarwidth, this.barH);
	}
}

 

Is the issue that I'm extending Gui? I'm doing that so I can use the "drawTexturedModalRect()" method for drawing. And "ScaledResolution" for positioning.
EDIT: in the attached image LEFT is my modded version, RIGHT is vanilla

MissingXPBar.png

Edited by hugo_the_dwarf
Changing Title to indicate SOLVED

6 minutes ago, hugo_the_dwarf said:

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

After you are done rendering your stuff you need to rebind the texture that was previously used. Forge won't rebind the texture after each even it posts in GuiIngameForge, it leaves it to modders(and that is the way it should be). The numbers are still drawn as FontRenderer binds the font texture every time it needs to draw anything.

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.