Jump to content

[SOLVED] [1.8] Having multiple effects gives wrong icons


Recommended Posts

Posted

So i'm implementing the Buff Status Bar from the Minecraft Forge Wiki, the bar itself works fine but i've tried adding under the icon the duration of the effect. Duration works as well, is displayed correctly, but the icon for the effects are wrong :/ So here is the status bar class

package blaze.events;

import java.util.Collection;
import java.util.Iterator;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
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;

public class GUIBuffBar extends Gui
{
private Minecraft mc;
FontRenderer fontRender;

public GUIBuffBar(Minecraft mc)
{
	super();

	this.mc = mc;
}

private static final int BUFF_ICON_SIZE = 18;
private static final int BUFF_ICON_SPACING = BUFF_ICON_SIZE + 5; // 2 pixels between buff icons
private static final int BUFF_ICON_BASE_U_OFFSET = 0;
private static final int BUFF_ICON_BASE_V_OFFSET = 198;
private static final int BUFF_ICONS_PER_ROW = 8;

@SubscribeEvent(priority = EventPriority.NORMAL)
public void onRenderExperienceBar(RenderGameOverlayEvent event)
{
	if(event.isCancelable() || event.type != ElementType.EXPERIENCE)
	{      
		return;
	}

	int xPos = 2;
	int yPos = 2;
	fontRender = mc.fontRendererObj;
	Collection collection = this.mc.thePlayer.getActivePotionEffects();
	if (!collection.isEmpty())
	{

		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		GL11.glDisable(GL11.GL_LIGHTING);      
		this.mc.renderEngine.bindTexture(new ResourceLocation("textures/gui/container/inventory.png"));      

		for (Iterator iterator = this.mc.thePlayer.getActivePotionEffects().iterator(); iterator.hasNext(); xPos += BUFF_ICON_SPACING)
		{
			PotionEffect potioneffect = (PotionEffect) iterator.next();
			Potion potion = Potion.potionTypes[potioneffect.getPotionID()];

			if (potion.hasStatusIcon())
			{
				int iconIndex = potion.getStatusIconIndex();
				this.drawTexturedModalRect(
						xPos, yPos, 
						BUFF_ICON_BASE_U_OFFSET + iconIndex % BUFF_ICONS_PER_ROW * BUFF_ICON_SIZE, BUFF_ICON_BASE_V_OFFSET + iconIndex / BUFF_ICONS_PER_ROW * BUFF_ICON_SIZE,
						BUFF_ICON_SIZE, BUFF_ICON_SIZE);
				fontRender.drawStringWithShadow(potion.getDurationString(potioneffect), xPos, yPos + 20, 0xFFFFFF);
			}       
		}
	}
}
}

 

And this is what it looks like when multiple effects are active

Qpagq9T.png

Thanks in advance for all who will help me :)

Don't blame me if i always ask for your help. I just want to learn to be better :)

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



×
×
  • Create New...

Important Information

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