Jump to content

Recommended Posts

Posted

I have a some mana bars that get rendered on to the screen, the catch is that it only works when I have a stack of 2 feathers in my hotbar and I have no idea why or how that could possibly effect it.

My CustomHud

 

 

public class CustomHud{

private static LuxinBarRenderer[] bar_Lux;

public CustomHud(){
	Minecraft mc = Minecraft.getMinecraft();
	Collection<ILuxin> luxin = LuxinReg.RegisteredLuxin.values();
	bar_Lux = new LuxinBarRenderer[luxin.size()];
	int index = 0;
	for(ILuxin lux : luxin)
	{
		LogHelper.info("rendering " + lux.GetName());
		bar_Lux[index] = new LuxinBarRenderer(lux.GetName(), mc, index, lux.GetColor());
		index++;
	}
}

@SubscribeEvent()//receiveCanceled=false)
public void onEvent(RenderGameOverlayEvent.Post event) {
	if(event.getType() == ElementType.ALL)
		renderHud();
}

public void renderHud()
{
	for( LuxinBarRenderer rend : bar_Lux)
		rend.RenderLuxinBar();
}

}

 

 

The Bar that gets rendered

 

public class LuxinBarRenderer {

private final static int BAR_WIDTH = 81;
private final static int BAR_HEIGHT = 9;
private final static int BAR_SPACING = 3;

private String lux;
private Minecraft mc;
private int iteration;
private int[] RGB;

public LuxinBarRenderer(String lux, Minecraft mc, int iteration, int[] RGB)
{
	this.lux = lux;
	this.mc = mc;
	this.iteration = iteration;
	this.RGB = RGB;
}

public void RenderLuxinBar()
{
	EntityPlayerSP player = mc.thePlayer;
	if(player == null)
		return;

	IDrafter drafter = DraftingProvider.get(player);
	if( drafter == null && !(drafter instanceof DefaultDrafter))
		return;
	DefaultDrafter prop = (DefaultDrafter) drafter;
	float avail = prop.GetAvailableLuxin().get(lux);
	float cap = prop.GetMaxLuxin().get(lux);
	LogHelper.info("Rendering " + RGB[0] + " " + RGB[1] + " " + RGB[2]);
	float percent = cap / avail;
	GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
	GL11.glPushMatrix();

	GL11.glColor4f((float)RGB[0]/255, (float)RGB[1]/255, (float)RGB[2]/255, .5f);

	int top = BAR_SPACING + (iteration * (BAR_SPACING + BAR_HEIGHT));
	int left = BAR_SPACING;
	GL11.glBegin(GL11.GL_LINE_LOOP);
	{
		GL11.glVertex2i(left, top);
		GL11.glVertex2i(left + BAR_WIDTH, top);
		GL11.glVertex2i(left + BAR_WIDTH, top + BAR_HEIGHT);
		GL11.glVertex2i(left, top + BAR_HEIGHT);
	}
	GL11.glEnd();
	GL11.glColor4f((float)RGB[0]/255f, (float)RGB[1]/255f, (float)RGB[2]/255f, 1f);
	GL11.glBegin(GL11.GL_QUADS);
	{
		int right = left + (int)(new Float(BAR_WIDTH) / percent);
		GL11.glVertex2i(left, top);
		GL11.glVertex2i(left, top + BAR_HEIGHT);
		GL11.glVertex2i(right, top + BAR_HEIGHT);
		GL11.glVertex2i(right, top);			
	}
	GL11.glEnd();
	GL11.glPopMatrix();
	GL11.glPopAttrib();
}
}

 

 

The log helper you see in the Bar renderer prints out the correct color values regardless of if the bar actually renders.

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Posted

Is it only with exactly 2 feathers, or can it be 2+ of any item? If it's the latter, it could be a bug with Forge / Minecraft as the extra layer that renders for the stack size might be doing something funky (it's happened before), or you may want to try using a different ElementType such as EXPERIENCE_BAR during the RenderGameOverlayEvent.Post.

Posted

Ok ... new problem.

 

With nothing in my hotbar the Bars render properly.

when I have one of my items(with a custom model loader) the colors of the bars change.

when my item is not selected the bars turn black.

having a stack of 2 of any other item makes the Bars render correctly regardless of selected item.

 

Edit: If I look around really fast it will occasionally show the correct colors for a moment.

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

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.

×
×
  • Create New...

Important Information

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