Skip to content

Instantly share code, notes, and snippets.

Created March 11, 2012 03:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2014869 to your computer and use it in GitHub Desktop.
Save anonymous/2014869 to your computer and use it in GitHub Desktop.
rendercaption
package net.minecraft.src;
/* this code goes where sounds are instanced
renderCaption newRenderCaption = new renderCaption();
// store s in public field
newRenderCaption.doRenderCaption(this, posX, posY, posZ, 9.0f, 0.0f);
*/
import net.minecraft.client.Minecraft;
import org.lwjgl.opengl.GL11;
public class renderCaption extends Render
{
protected RenderManager renderManager;
public renderCaption()
{
// initialize public field here where subtitle string is got from
}
// subclass must implement abstract method = doRender(T entity, double d, double d1, double d2, float f, float f1).
/**
* Draws the debug or playername text above a living
*/
// Renders sound subtitles - will get sound string from a public field
// doRender(T entity, double d, double d1, double d2, float f, float f1). <- must be using this
public void doRenderCaption(EntityLiving par1EntityLiving, double par3, double par5, double par7, float par9, float par10)
{
float f = par1EntityLiving.getDistanceToEntity(renderManager.livingPlayer);
if (f > (float)par9)
{
return;
}
// get subtitleText(par2Str)
// to do : inputs par2Str and returns string to display
String par2Str = "Mobby";
FontRenderer fontrenderer = getFontRendererFromRenderManager();
float f1 = 1.6F;
float f2 = 0.01666667F * f1;
GL11.glPushMatrix();
GL11.glTranslatef((float)par3 + 0.0F, (float)par5 + 2.3F, (float)par7);
GL11.glNormal3f(0.0F, 1.0F, 0.0F);
GL11.glRotatef(-renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
GL11.glRotatef(renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
GL11.glScalef(-f2, -f2, f2);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDepthMask(false);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
Tessellator tessellator = Tessellator.instance;
GL11.glDisable(GL11.GL_TEXTURE_2D);
tessellator.startDrawingQuads();
int i = fontrenderer.getStringWidth(par2Str) / 2;
tessellator.setColorRGBA_F(0.0F, 0.0F, 0.0F, 0.25F);
tessellator.addVertex(-i - 1, -1 + 0, 0.0D);
tessellator.addVertex(-i - 1, 8 + 0, 0.0D);
tessellator.addVertex(i + 1, 8 + 0, 0.0D);
tessellator.addVertex(i + 1, -1 + 0, 0.0D);
tessellator.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
fontrenderer.drawString(par2Str, -fontrenderer.getStringWidth(par2Str) / 2, 0, 0x20ffffff);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthMask(true);
fontrenderer.drawString(par2Str, -fontrenderer.getStringWidth(par2Str) / 2, 0, -1);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_BLEND);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glPopMatrix();
}
/**
* Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
* handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
* (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
* double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
*/
public void doRender(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par9, float par10)
{
doRenderCaption((EntityLiving)par1EntityLiving, par2, par4, par6, par9, par10);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment