Jump to content

Draw GUI-Icons over player


NiceDev

Recommended Posts

Hello,

I decompiled a mod, that allows to draw the health and food-level over the player.

Now it draws some white chars over the player, I think there is something wrong with the "drawTexturedModalRect"-method, but I am too stupid to find the error, because I never worked with "addVertexWithUV" before. Can you help me?

 

CS7wYDw.png

package me.hyperion.mod;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityOtherPlayerMP;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.util.MathHelper;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.common.MinecraftForge;

import org.lwjgl.opengl.GL11;

public class RenderPlayerCustom extends RenderPlayer {

public boolean show_health = true;
public boolean show_armor = true;
public boolean show_food_stats = false;

@Override
protected void passSpecialRender(EntityLivingBase par1EntityLivingBase,
		double par2, double par4, double par6) {
	if (MinecraftForge.EVENT_BUS.post(new RenderLivingEvent.Specials.Pre(
			par1EntityLivingBase, this, par2, par4, par6)))
		return;
	GL11.glAlphaFunc(516, 0.1F);

	if (func_110813_b(par1EntityLivingBase)) {
		float f = 1.6F;
		float f1 = 0.01666667F * f;
		double d3 = par1EntityLivingBase
				.getDistanceSqToEntity(this.renderManager.livingPlayer);
		float f2 = par1EntityLivingBase.isSneaking() ? NAME_TAG_RANGE_SNEAK
				: NAME_TAG_RANGE;

		if (d3 < f2 * f2) {
			String s = par1EntityLivingBase.func_145748_c_()
					.getFormattedText();

			if (par1EntityLivingBase.isSneaking()) {
				FontRenderer fontrenderer = getFontRendererFromRenderManager();
				GL11.glPushMatrix();
				GL11.glTranslatef((float) par2 + 0.0F, (float) par4
						+ par1EntityLivingBase.height + 0.5F,
						(float) par6);
				GL11.glNormal3f(0.0F, 1.0F, 0.0F);
				GL11.glRotatef(-this.renderManager.playerViewY, 0.0F,
						1.0F, 0.0F);
				GL11.glRotatef(this.renderManager.playerViewX, 1.0F,
						0.0F, 0.0F);
				GL11.glScalef(-f1, -f1, f1);
				GL11.glDisable(2896);
				GL11.glTranslatef(0.0F, 0.25F / f1, 0.0F);
				GL11.glDepthMask(false);
				GL11.glEnable(3042);
				OpenGlHelper.glBlendFunc(770, 771, 1, 0);
				Tessellator tessellator = Tessellator.instance;
				GL11.glDisable(3553);
				tessellator.startDrawingQuads();
				int i = fontrenderer.getStringWidth(s) / 2;
				tessellator.setColorRGBA_F(0.0F, 0.0F, 0.0F, 0.25F);
				tessellator.addVertex(-i - 1, -1.0D, 0.0D);
				tessellator.addVertex(-i - 1, 8.0D, 0.0D);
				tessellator.addVertex(i + 1, 8.0D, 0.0D);
				tessellator.addVertex(i + 1, -1.0D, 0.0D);
				tessellator.draw();
				GL11.glEnable(3553);
				GL11.glDepthMask(true);
				fontrenderer.drawString(s,
						-fontrenderer.getStringWidth(s) / 2, 0, 553648127);
				GL11.glEnable(2896);
				GL11.glDisable(3042);
				GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
				GL11.glPopMatrix();
			} else {
				func_96449_a(par1EntityLivingBase, par2, par4, par6, s, f1,
						d3);
			}
		}
	}
	MinecraftForge.EVENT_BUS.post(new RenderLivingEvent.Specials.Post(
			par1EntityLivingBase, this, par2, par4, par6));
}

@Override
protected void func_147906_a(Entity p_147906_1_, String p_147906_2_,
		double p_147906_3_, double p_147906_5_, double p_147906_7_,
		int p_147906_9_) {
	double d3 = p_147906_1_.getDistanceSqToEntity(this.renderManager.livingPlayer);

	if (d3 <= p_147906_9_ * p_147906_9_) {
		FontRenderer fontrenderer = getFontRendererFromRenderManager();
		float f = 1.6F;
		float f1 = 0.01666667F * f;
		GL11.glPushMatrix();
		GL11.glTranslatef((float) p_147906_3_ + 0.0F, (float) p_147906_5_
				+ p_147906_1_.height + 0.5F, (float) p_147906_7_);
		GL11.glNormal3f(0.0F, 1.0F, 0.0F);
		GL11.glRotatef(-this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
		GL11.glRotatef(this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
		GL11.glScalef(-f1, -f1, f1);
		GL11.glDisable(2896);
		GL11.glDepthMask(false);
		GL11.glDisable(2929);
		GL11.glEnable(3042);
		OpenGlHelper.glBlendFunc(770, 771, 1, 0);
		Tessellator tessellator = Tessellator.instance;
		byte b0 = 0;

		if (p_147906_2_.equals("deadmau5")) {
			b0 = -10;
		}

		GL11.glDisable(3553);
		tessellator.startDrawingQuads();
		int j = fontrenderer.getStringWidth(p_147906_2_) / 2;
		tessellator.setColorRGBA_F(0.0F, 0.0F, 0.0F, 0.25F);
		tessellator.addVertex(-j - 1, -1 + b0, 0.0D);
		tessellator.addVertex(-j - 1, 8 + b0, 0.0D);
		tessellator.addVertex(j + 1, 8 + b0, 0.0D);
		tessellator.addVertex(j + 1, -1 + b0, 0.0D);
		tessellator.draw();
		GL11.glEnable(3553);
		fontrenderer.drawString(p_147906_2_,
				-fontrenderer.getStringWidth(p_147906_2_) / 2, b0, 553648127);
		GL11.glEnable(2929);
		GL11.glDepthMask(true);
		fontrenderer.drawString(p_147906_2_,
				-fontrenderer.getStringWidth(p_147906_2_) / 2, b0, -1);

		int y = 0;

		Minecraft mc = Minecraft.getMinecraft();

		EntityOtherPlayerMP player = (EntityOtherPlayerMP) p_147906_1_;

		mc.getTextureManager().bindTexture(Gui.icons);

		if (show_health) {
			int k4 = 0;

			IAttributeInstance iattributeinstance = player
					.getEntityAttribute(SharedMonsterAttributes.maxHealth);

			f = (float) iattributeinstance.getAttributeValue();
			f1 = player.getHealth();
			int k = MathHelper.ceiling_float_int(player.getHealth());
			int l = MathHelper.ceiling_float_int(player.prevHealth);
			float f2 = f1;
			y = -10;

			if (f1 > 0.0F) {
				y = (int) (y - 10.0F);
			}

			for (int k3 = MathHelper.ceiling_float_int((f + f1) / 2.0F) - 1; k3 >= 0; k3--) {
				int l3 = 16;

				b0 = 0;

				int i4 = MathHelper.ceiling_float_int(k3 + 1 / 10.0F) - 1;
				int j4 = k3 % 10 * 8 - 40;

				byte b1 = 0;

				if (f2 > 0.0F) {
					drawTexturedModalRect(j4, -20, 16 + b0 * 9, 9 * b1, 9,
							9);

					if ((f2 == f1) && (f1 % 2.0F == 1.0F))
						drawTexturedModalRect(j4, -20, l3 + 153, 9 * b1, 9,
								9);
					else {
						drawTexturedModalRect(j4, -20, l3 + 144, 9 * b1, 9,
								9);
					}

					f2 -= 2.0F;
				} else {
					drawTexturedModalRect(j4, -10, 16 + b0 * 9, 9 * b1, 9,
							9);

					if (k3 * 2 + 1 < k) {
						drawTexturedModalRect(j4, -10, l3 + 36, 9 * b1, 9,
								9);
					}

					if (k3 * 2 + 1 == k) {
						drawTexturedModalRect(j4, -10, l3 + 45, 9 * b1, 9,
								9);
					}

				}

			}

		}

		if (show_armor) {
			int i3 = player.getTotalArmorValue();

			y -= 10;

			for (int k3 = 0; k3 < 10; k3++) {
				if (i3 > 0) {
					int l3 = k3 * 8 - 40;

					if (k3 * 2 + 1 < i3) {
						drawTexturedModalRect(l3, y, 34, 9, 9, 9);
					}

					if (k3 * 2 + 1 == i3) {
						drawTexturedModalRect(l3, y, 25, 9, 9, 9);
					}

					if (k3 * 2 + 1 > i3) {
						drawTexturedModalRect(l3, y, 16, 9, 9, 9);
					}
				}
			}

		}

		if (show_food_stats) {
			int i1 = player.getFoodStats().getFoodLevel();

			y -= 10;

			for (int l3 = 0; l3 < 10; l3++) {
				byte b4 = 0;

				int k4 = l3 * 8 - 40;
				drawTexturedModalRect(k4, y, 16 + b4 * 9, 27, 9, 9);

				if (l3 * 2 + 1 < i1) {
					drawTexturedModalRect(k4, y, 52, 27, 9, 9);
				}

				if (l3 * 2 + 1 == i1) {
					drawTexturedModalRect(k4, y, 61, 27, 9, 9);
				}
			}
		}

		GL11.glEnable(2896);
		GL11.glDisable(3042);
		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		GL11.glPopMatrix();
	}
}

public void drawTexturedModalRect(int par1, int par2, int par3, int par4,
		int par5, int par6) {
	float f = 0.0039063F;
	float f1 = 0.0039063F;
	Tessellator tessellator = Tessellator.instance;
	tessellator.startDrawingQuads();
	tessellator.addVertexWithUV(par1 + 0, par2 + par6, 0.0D, par3 + 0 * f,
			par4 + par6 * f1);
	tessellator.addVertexWithUV(par1 + par5, par2 + par6, 0.0D, par3 + par5
			* f, par4 + par6 * f1);
	tessellator.addVertexWithUV(par1 + par5, par2 + 0, 0.0D, par3 + par5 * f,
			par4 + 0 * f1);
	tessellator.addVertexWithUV(par1 + 0, par2 + 0, 0.0D, par3 + 0 * f, par4
			+ 0 * f1);
	tessellator.draw();
}
}

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



×
×
  • Create New...

Important Information

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