Jump to content

Render Nameplate or image above mob


charsmud

Recommended Posts

I replaced the RenderLivingEvent with RenderLivingEvent.Specials.Pre and it worked!  However, it's over the player's head but not the villager (which I thought I prevented in my VillagerBubbleHandler):

 

 

package village.mechanics;


import net.minecraft.entity.passive.EntityVillager;
import net.minecraftforge.client.event.RenderLivingEvent;
import net.minecraftforge.event.ForgeSubscribe;
import cpw.mods.fml.client.FMLClientHandler;

public class VillagerBubbleHandler
{
public VillagerBubbleHandler()
{
}
@ForgeSubscribe
public void onVillagerRender(RenderLivingEvent.Specials.Pre event )
{
	VillageMechanics mechanics = new VillageMechanics();

	if(event.entity instanceof EntityVillager)
	{
		System.out.println("EXECUTED FROM VILLAGERBUBBLEHANDLER");
		mechanics.updateTradeBubble(FMLClientHandler.instance().getClient());
	}
}

}

 

 

Also, the image is distorted like this:

 

SK7E557.png

 

Any ideas? 

Link to comment
Share on other sites

yes, congrats

 

now this happens because when you are rendering the quad, opengl still thinks that you want to render at the current position, it doesnt move the things around for you

 

so you need to translate the openGL matrix to the position of the villager

 

now when you're drawing, 0, 0, 0 is considered the position of the main player, so you need to translate by the difference between you and the target entity

 

GL11.glPushMatrix();//save current gl transform state
GL11.glTranslated(diffX, diffY, diffZ);

//usual render bubble code

GL11.glPopMatrix();//restore saved gl transform state

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

not lines xD

 

too lazy to type out full code *yawn*

 

Also, I'm not sure if the tessellator takes partial ticks into account.  I've just heard nasty things about it so I dont really ever plan on using it.  I guess I'm just one paranoid fellow.  I'll grind out the openGL for now, or at least until my fingers get numb.

 

if it doesn't take into account partial ticks, heres some code to help you out:

	//get the villager variable in whatever way you do it...  not sure how you have it set up.
                EntityClientPlayerMP player = mc.thePlayer;
	double diffX = (villager.prevPosX + (villager.posX - villager.prevPosX) * partialTicks) - (player.prevPosX + (player.posX - player.prevPosX) * partialTicks); 
	double diffY = (villager.prevPosY + (villager.posY - villager.prevPosY) * partialTicks) - (player.prevPosY + (player.posY - player.prevPosY) * partialTicks); 
                double diffZ = (villager.prevPosZ + (villager.posZ - villager.prevPosZ) * partialTicks) - (player.prevPosZ + (player.posZ - player.prevPosZ) * partialTicks); 

 

edit:  you get partialticks for this from the event renderWorldLastEvent

Link to comment
Share on other sites

I've just heard nasty things about it so I dont really ever plan on using it.

its actually a very powerfull tool if you know how to use it

 

Also, I'm not sure if the tessellator takes partial ticks into account.

it doesn't, but it's lot like openGL takes care of it either (you have to take that into account manually)

 

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Ok, I was able to translate it over to the Entity.  However, I think my billboarding is messed up....  The texture is also not over the villager (I have NO idea how to fix this.  xD)  The texture is still screwy like this as well:

 

 

BfE7PTi.png

 

 

package village.mechanics;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraftforge.client.event.RenderLivingEvent;

import org.lwjgl.opengl.GL11;


/**
* Contains information about the new Mechanics for the past
* @author Charsmud
*
*/
public class VillageMechanics
{
/**
 * Updates Paradox Bar and Renders
 * @param minecraft
 * @param amtOfParadox
 */
public void updateTradeBubble(Minecraft minecraft, RenderLivingEvent.Specials.Pre event)
{
	System.out.println("EXECUTED FROM VILLAGEMECHANICS");
        Tessellator tessellator = Tessellator.instance;

        
        EntityClientPlayerMP player = minecraft.thePlayer;
        
        double diffX = (event.entity.prevPosX + (event.entity.posX - event.entity.prevPosX)) - (player.prevPosX + (player.posX - player.prevPosX)); 
        double diffY = (event.entity.prevPosY + (event.entity.posY - event.entity.prevPosY)) - (player.prevPosY + (player.posY - player.prevPosY)); 
        double diffZ = (event.entity.prevPosZ + (event.entity.posZ - event.entity.prevPosZ)) - (player.prevPosZ + (player.posZ - player.prevPosZ));
        
        GL11.glPushMatrix();//save current gl transform state
        GL11.glTranslated(diffX, diffY, diffZ);

        GL11.glRotatef(-RenderManager.instance.playerViewY, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(RenderManager.instance.playerViewX, 1.0F, 0.0F, 0.0F);

        
	minecraft.renderEngine.bindTexture("/village/images/bubble1.png");
	tessellator.startDrawingQuads();
	tessellator.addVertexWithUV(1, 1, 0, 0, 0);
	tessellator.addVertexWithUV(1, 1, 0+2, 0, 1);
	tessellator.addVertexWithUV(1+1, 1+2, 0, 1, 1);
	tessellator.addVertexWithUV(1, 1+1, 0, 1, 0);

        tessellator.addVertexWithUV(1, 1, 0, 0, 0);
	tessellator.addVertexWithUV(1, 1+1, 0, 1, 0);
	tessellator.addVertexWithUV(1+1, 1+2, 0, 1, 1);
	tessellator.addVertexWithUV(1, 1, 0+2, 0, 1);
	tessellator.draw();

        GL11.glPopMatrix();//restore saved gl transform state

}
}

 

 

OFF-TOPIC: I was going to learn OGL, but I decided with DirectX instead, as OGL was just a bunch of states that were enabled or disabled.... :P

 

Link to comment
Share on other sites

as OGL was just a bunch of states that were enabled or disabled

heu lets not get started with this because i actually prefer openGL to d3dx but lets say that d3dx has more noob-friendly tools and openGL has more access to your ressource.....

 

 

GL11.glRotatef(-RenderManager.instance.playerViewY, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(RenderManager.instance.playerViewX, 1.0F, 0.0F, 0.0F);

 

you want spherical billboarding or cylindrical billboarding ? what you did is for spherical

also i think using i saw in some other thread that RenderManager values were messed up

i think its better to use

entityPlayer.rotationYaw (for Y)

entityPlayer.rotationPitch (for X)

 

 

next:

tessellator.addVertexWithUV(1, 1, 0, 0, 0);
tessellator.addVertexWithUV(1, 1, 0+2, 0, 1);
tessellator.addVertexWithUV(1+1, 1+2, 0, 1, 1);
tessellator.addVertexWithUV(1, 1+1, 0, 1, 0);

 

you have a bunch of extra 1 there

after you did glTranslated(x, y, z) you are directly at the position of the villager

so adding 1 (in the x column, the extra 1 in the y column will make the image be right above the entity,not in it :P) will move your quad by 1 unit in the x direction

 

something centered would look like thsi:

tessellator.addVertexWithUV(-1, 1, 1, 0, 0);
tessellator.addVertexWithUV(-1, 1, -1, 0, 1);
tessellator.addVertexWithUV(1, 1, -1, 1, 1);
tessellator.addVertexWithUV(1, 1, 1, 1, 0);

not saying its the right orientation, jsut saying it would be more centered

 

dont forget to put both planes (and remove the useless one later)

 

tessellator.addVertexWithUV(-1, 1, 1, 0, 0);
tessellator.addVertexWithUV(-1, 1, -1, 0, 1);
tessellator.addVertexWithUV(1, 1, -1, 1, 1);
tessellator.addVertexWithUV(1, 1, 1, 1, 0);

tessellator.addVertexWithUV(-1, 1, 1, 0, 0);
tessellator.addVertexWithUV(1, 1, 1, 1, 0);
tessellator.addVertexWithUV(1, 1, -1, 1, 1);
tessellator.addVertexWithUV(-1, 1, -1, 0, 1);

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

OK, so the image is now centered.  :)  I changed the rotation to this:

 

        GL11.glRotatef(-player.rotationYaw, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(player.rotationPitch, 1.0F, 0.0F, 0.0F);

 

And now it rotates wierdly....  I probably want cylindrical billboarding (that's just spinning in the center axis, right?  xD). 

 

Off-Topic:  let's not get into Direct3D vs OGL, that never ends well, and they both have their benefits.  :)

Link to comment
Share on other sites

and they both have their benefits.

no, not d3dx ... ahahah just kidding *stfu hydroflame*

 

 

yes cylindrical billboarding would be just aroudn the y axis, if that what you want

remove:

 GL11.glRotatef(player.rotationPitch, 1.0F, 0.0F, 0.0F);

this line tell openGL to rotate to face you on a "up-down" way

 

while the other one makes the billboard face you in a "left-right" way

 

 

And now it rotates wierdly

what do you mean by that ? it "jumps/ lag ?

 

or some other visual bug

 

if its the lag you want to do the same as you did with the position using "partialTicks"

 

partialTick hold the current "percentage" of the frame completed, what happens if that you are rendering the screen many more times then you are updating the position and orientation of the characters. so partialTicks tell you how much of the frame is done so far, 25%? 50? 75? 90?

by using it you can interpolate between the last known position and the "current position"

 

 

        (1)                      (2)                    (3)                      (4)

villager.prevPosX + (villager.posX - villager.prevPosX) * partialTicks

 

 

so you take the difference between 2 and 3, thsi gives you the movement different that the character did in the last frame

multiply by 4 gives you how much of the frame we are done, then add 1 will give you technicly where the character was ~20 tick ago (since position is updated every 20 tick)

so yes technicly what you are seeing is always the past of the actual player mouvement. but this isnt call of duty or another fast space game so this method is somewhat ok to use

 

off-topic

a real method would be to try to predict player movement, aka, if the player is going foward in a tunnel, chances are hes not goign to suddently stop and look at the wall :P

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

it would be a possibility, but openGL (specially version 1) has some utility method to do that

remember when we said you need to translate the iamge to the position of the mob ? well you can also translate it from there after that (and rotate it)

 

//setup code to get the matrxi to the right position

GL11.glTranslated(0, 0.5, 0);//move the whole thing 0.5 unit in the air
GL11.glRotated(90, 0, 1, 0);//rotate around the y axis by 90 degree

//WATCHOUT, doing translate THEN rotate wil not give the same result as rotate THEN translate
(also, it might be -90 instead of +90, not sure what your specific case needs)

//resotre core

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

I am translating then rotating.  Here's the rotating + translating code:

 

 

        GL11.glTranslated(diffX, diffY + 3, diffZ);

        //GL11.glTranslated(0, 3, 0);//move the whole thing 0.5 unit in the air
        GL11.glRotatef(-90, 1, 0, 0);//rotate around the y axis by 90 degree

        GL11.glRotatef(-player.rotationYaw, 0.0F, 0.0F, 1.0F);

 

 

And here's the whole file:

 

 

package village.mechanics;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraftforge.client.event.RenderLivingEvent;

import org.lwjgl.opengl.GL11;


/**
* Contains information about the new Mechanics for the past
* @author Charsmud
*
*/
public class VillageMechanics
{
/**
 * Updates Paradox Bar and Renders
 * @param minecraft
 * @param amtOfParadox
 */
public void updateTradeBubble(Minecraft minecraft, RenderLivingEvent.Specials.Pre event)
{
	System.out.println("EXECUTED FROM VILLAGEMECHANICS");
        Tessellator tessellator = Tessellator.instance;

        
        EntityClientPlayerMP player = minecraft.thePlayer;
        
        double diffX = (event.entity.prevPosX + (event.entity.posX - event.entity.prevPosX)) - (player.prevPosX + (player.posX - player.prevPosX)); 
        double diffY = (event.entity.prevPosY + (event.entity.posY - event.entity.prevPosY)) - (player.prevPosY + (player.posY - player.prevPosY)); 
        double diffZ = (event.entity.prevPosZ + (event.entity.posZ - event.entity.prevPosZ)) - (player.prevPosZ + (player.posZ - player.prevPosZ));
        
        GL11.glPushMatrix();
        GL11.glTranslated(diffX, diffY + 3, diffZ);

        //GL11.glTranslated(0, 3, 0);//move the whole thing 0.5 unit in the air
        GL11.glRotatef(-90, 1, 0, 0);//rotate around the y axis by 90 degree

        GL11.glRotatef(-player.rotationYaw, 0.0F, 0.0F, 1.0F);


        
	minecraft.renderEngine.bindTexture("/village/images/bubble1.png");
	tessellator.startDrawingQuads();
	tessellator.addVertexWithUV(-1, 1, 1, 0, 0);
	tessellator.addVertexWithUV(-1, 1, -1, 0, 1);
	tessellator.addVertexWithUV(1, 1, -1, 1, 1);
	tessellator.addVertexWithUV(1, 1, 1, 1, 0);

	tessellator.addVertexWithUV(-1, 1, 1, 0, 0);
	tessellator.addVertexWithUV(1, 1, 1, 1, 0);
	tessellator.addVertexWithUV(1, 1, -1, 1, 1);
	tessellator.addVertexWithUV(-1, 1, -1, 0, 1);
	tessellator.draw();

        GL11.glPopMatrix();//restore saved gl transform state

}
}

 

Link to comment
Share on other sites

Tessellator tessellator = Tessellator.instance;

 

       

        EntityClientPlayerMP player = minecraft.thePlayer;

       

        double diffX = (event.entity.prevPosX + (event.entity.posX - event.entity.prevPosX)) - (player.prevPosX + (player.posX - player.prevPosX));

        double diffY = (event.entity.prevPosY + (event.entity.posY - event.entity.prevPosY)) - (player.prevPosY + (player.posY - player.prevPosY));

        double diffZ = (event.entity.prevPosZ + (event.entity.posZ - event.entity.prevPosZ)) - (player.prevPosZ + (player.posZ - player.prevPosZ));

       

        GL11.glPushMatrix();

        GL11.glTranslated(diffX, diffY + 3, diffZ);

        GL11.glRotatef(-player.rotationYaw, 0.0F, 0.0F, 1.0F);

        GL11.glPushMatrix();

 

        GL11.glRotatef(-90, 1, 0, 0);//noted 1

        GL11.glTranslated(0, 3, 0);//noted 2

 

 

 

       

minecraft.renderEngine.bindTexture("/village/images/bubble1.png");

tessellator.startDrawingQuads();

tessellator.addVertexWithUV(-1, 1, 1, 0, 0);//your +1 everywhere in y is redundant btw it should be included in a glTranslated

tessellator.addVertexWithUV(-1, 1, -1, 0, 1);

tessellator.addVertexWithUV(1, 1, -1, 1, 1);

tessellator.addVertexWithUV(1, 1, 1, 1, 0);

 

tessellator.addVertexWithUV(-1, 1, 1, 0, 0);

tessellator.addVertexWithUV(1, 1, 1, 1, 0);

tessellator.addVertexWithUV(1, 1, -1, 1, 1);

tessellator.addVertexWithUV(-1, 1, -1, 0, 1);

tessellator.draw();

 

        GL11.glPopMatrix();

        GL11.glPopMatrix();//restore saved gl transform state

 

try this instead, if that acts weird, switch the line commented "noted 1" and "noted 2"

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

oh

GL11.glRotatef(-player.rotationYaw, 0.0F, 0.0F, 1.0F);

you had that ^ i copied it without thinking

 

 

change it to thjat

GL11.glRotatef(-player.rotationYaw, 0.0F, 1.0F, 0.0F);

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

well ... this is getting hard besaude its like 1 line to switch or not, so either wait til i have time to do it manually or try to play around to make it fit correctly okay ? :\

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Figured it out!  :D  After some experimentation, I figured out that this line was controlling the distance from the center:

        GL11.glTranslated(0, 3, 0);//noted 2

 

I changed i to 0, -1, 0 and it was right above the head!  :D  Thanks very much for all the help! :)

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.

×
×
  • Create New...

Important Information

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