Jump to content

Recommended Posts

Posted

What I wondering is how does vanilla render things such as a player name/entity name tag above the entity and get it to take into account the world lighting, I have setup a sort of text render that renders above the horse to tell its stats but the text does not take into account the lighitng.

This is what it looks like:

2pzf921.png

 

This is the code:

 

 

        // Renders the text above the entity

public static void renderText(String[] text, float x, float y, float z, int color, boolean renderBlackBG, float partialTickTime)

{

float playerX = (float) (mc.thePlayer.lastTickPosX + (mc.thePlayer.posX - mc.thePlayer.lastTickPosX) * partialTickTime);

float playerY = (float) (mc.thePlayer.lastTickPosY + (mc.thePlayer.posY - mc.thePlayer.lastTickPosY) * partialTickTime);

float playerZ = (float) (mc.thePlayer.lastTickPosZ + (mc.thePlayer.posZ - mc.thePlayer.lastTickPosZ) * partialTickTime);

float dx = x - playerX;

float dy = y - playerY;

float dz = z - playerZ;

float distance = (float) Math.sqrt(dx * dx + dy * dy + dz * dz);

FontRenderer fontrenderer = mc.getRenderManager().getFontRenderer();

float f = 1.6F;

float f1 = 0.016666668F * f;

 

GlStateManager.pushMatrix();

GlStateManager.translate(dx, dy, dz);

GL11.glNormal3f(0.0F, 1.0F, 0.0F);

setupRendering(-f1, -f1, -f1);

Tessellator tessellator = Tessellator.getInstance();

WorldRenderer worldrenderer = tessellator.getWorldRenderer();

GlStateManager.disableDepth();

int textWidth = 0;

 

for (String message : text)

{

int messageWidth = fontrenderer.getStringWidth(message);

if (messageWidth > textWidth) textWidth = messageWidth;

}

 

int lineHeight = 10;

 

if (renderBlackBG)

{

GlStateManager.disableTexture2D();

worldrenderer.startDrawingQuads();

int j = textWidth / 2;

worldrenderer.setColorRGBA_F(0.0F, 0.0F, 0.0F, 0.5F);

worldrenderer.addVertex((double) (-j - 1), (double) (-1 + 0), 0.0D);

worldrenderer.addVertex((double) (-j - 1), (double) (8 + lineHeight * text.length - lineHeight), 0.0D);

worldrenderer.addVertex((double) (j + 1), (double) (8 + lineHeight * text.length - lineHeight), 0.0D);

worldrenderer.addVertex((double) (j + 1), (double) (-1 + 0), 0.0D);

tessellator.draw();

GlStateManager.enableTexture2D();

}

 

int i = 0;

 

for (String message : text)

{

GlStateManager.disableDepth();

fontrenderer.drawString(message, -textWidth / 2, i * lineHeight, 553648127);

GlStateManager.enableDepth();

fontrenderer.drawString(message, -textWidth / 2, i * lineHeight, color);

++i;

}

 

GlStateManager.enableLighting();

GlStateManager.depthMask(true);

GlStateManager.disableBlend();

GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

GlStateManager.popMatrix();

}

 

        // Renders the item above the entity

public static void renderItemIcon(float x, float y, float z, Item item, float partialTickTime)

{

RenderManager rendermanager = mc.getRenderManager();

float playerX = (float) (mc.thePlayer.lastTickPosX + (mc.thePlayer.posX - mc.thePlayer.lastTickPosX) * partialTickTime);

float playerY = (float) (mc.thePlayer.lastTickPosY + (mc.thePlayer.posY - mc.thePlayer.lastTickPosY) * partialTickTime);

float playerZ = (float) (mc.thePlayer.lastTickPosZ + (mc.thePlayer.posZ - mc.thePlayer.lastTickPosZ) * partialTickTime);

float dx = x - playerX;

float dy = y - playerY;

float dz = z - playerZ;

float scale = 0.025F;

 

GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

GlStateManager.pushMatrix();

GlStateManager.translate(dx, dy, dz);

rotateByView(mc.getRenderManager());

GlStateManager.scale(-scale, -scale, -scale);

GlStateManager.disableLighting();

if (AnimalInformation.showThroughBlocks) GlStateManager.disableDepth();

GlStateManager.enableBlend();

GlStateManager.blendFunc(770, 771);

GlStateManager.disableDepth();

GlStateManager.color(0.5F, 0.5F, 0.5F, 1.0F);

renderItemTexture(-8, -8, item, 16, 16);

GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

GlStateManager.enableDepth();

renderItemTexture(-8, -8, item, 16, 16);

GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

if (AnimalInformation.showThroughBlocks) GlStateManager.enableDepth();

GlStateManager.enableLighting();

GlStateManager.popMatrix();

}

 

        // Rotates the object based on the viewpoint

private static void rotateByView(RenderManager rendermanager)

{

GlStateManager.rotate(-rendermanager.playerViewY, 0.0F, 1.0F, 0.0F);

GlStateManager.rotate(Minecraft.getMinecraft().gameSettings.thirdPersonView != 2 ? rendermanager.playerViewX : -rendermanager.playerViewX, 1.0F, 0.0F, 0.0F);

}

 

        // Sets up the basic rendering

public static void setupRendering(float scaleX, float scaleY, float scaleZ)

{

rotateByView(mc.getRenderManager());

GlStateManager.scale(scaleX, scaleY, scaleZ);

GlStateManager.disableLighting();

GlStateManager.depthMask(false);

GlStateManager.disableDepth();

GlStateManager.enableBlend();

GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);

}

 

 

Posted

Random guess:

 

Have you tried

GL11.glDisable(GL11.GL_TEXTURE_2D);

?

 

I was doing some GL work a few weeks back and not having that disabled was causing what looked like lighting glitches.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Hi

 

You might get some useful clues from this code for rendering a TESR, if you want to turn world lighting on.

https://github.com/TheGreyGhost/MinecraftByExample/blob/master/src/main/java/minecraftbyexample/mbe21_tileentityspecialrenderer/TileEntitySpecialRendererMBE21.java

 

OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, SKY_LIGHT_VALUE * 16.0F, BLOCK_LIGHT_VALUE * 16.0F);

 

Alternatively, depending on the event you're using for your rendering, the EntityFX rendering might also have stuff of interest

Entity.getBrightnessForRender()  - in particular see

EffectRenderer.renderLitParticles()

and

EffectRenderer.renderParticles()

 

-TGG

 

Posted

So I have searched around for the setLightmapTextureCoords and the most common use is using Entity#getBrightnessForRender but when I apply that to my render, nothing changes, I also syso the value of the getBrightnessForRender, but that never changes either.

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.