Jump to content

Recommended Posts

Posted

Hey, I saw the post the other day asking how to draw images into the world and HyrdoFlame(I think his name is) explained how to do it (Heres the post: http://tinyurl.com/kwygvoc) but I thought why cant you just use drawTexturedModalRect so I tried and it didnt work. So I want to know why, since that method uses tessellator too

Posted

heard someone saying my name

 

yes you can, but drawTextureModelRectangle does a weird reshape of the texture, so it "works" in gui but in world it would probably look like shit

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

-hydroflame, author of the forge revolution-

Posted

heard someone saying my name

 

yes you can, but drawTextureModelRectangle does a weird reshape of the texture, so it "works" in gui but in world it would probably look like shit

Is there a way to draw a simple rectangle without an image. Im looking to do a health bar

Posted

without an image, no

BUT you can make a 1 pixel by 1 pixel image in *insert your favorite image editor here* (mine is paint.net, different from microsoft paint btw)

and make that a texture in minecraft

 

next you can load that texture and use tessellator.setColorOpaque(R, G, B) (or any other color altering function)

 

bind your texture:

Minecraft.getMinecraft().renderEngine.func_xxxx_x(BlankTexture);

set your color

and call this utility method

 

 

public static void drawTexturedQuadFit(double x, double y, double width, double height, double zLevel){

Tessellator tessellator = Tessellator.instance;

tessellator.setColorOpaque(255, 255, 255);

        tessellator.startDrawingQuads();

tessellator.setColorOpaque(255, 255, 255);

        tessellator.addVertexWithUV(x + 0, y + height, zLevel, 0,1);

        tessellator.addVertexWithUV(x + width, y + height, zLevel, 1, 1);

        tessellator.addVertexWithUV(x + width, y + 0, zLevel, 1,0);

        tessellator.addVertexWithUV(x + 0, y + 0, zLevel, 0, 0);

tessellator.setColorOpaque(255, 255, 255);

        tessellator.draw();

}

 

final code:

 

//in drawing method
mc.renderEngine.func_110577_a(blankTexture);//blankTexture is a ResourceLocation btw
RenderHelper.drawTexturedQuadFit(xPosition, yPosition, height, height, 0);

 

remember, drawing a width, height of 1, 1 in the minecraft world represent the size of a block,    1x1 in a gui represent 1 pixel

 

so 100x100 in the world is HUGE but in your gui is like the length of the health bar

 

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

-hydroflame, author of the forge revolution-

Posted

Hm, didnt seem to render. Heres the code:

	@ForgeSubscribe
public void renderCavemanHealthBar(RenderLivingEvent.Specials.Pre event)
{
	mc = mc.getMinecraft();
	GuiIngame gui = mc.ingameGUI;
	if(event.entity instanceof AC_EntityCaveman)
	{

		System.out.println("Drawing Rect");
		Tessellator tessellator = Tessellator.instance;

		EntityClientPlayerMP player = mc.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, 1.0F, 0.0F);
		GL11.glPushMatrix();

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

		mc.func_110434_K().func_110577_a(new ResourceLocation(Strings.MOD_ID, "/textures/gui/temperature_bar.png"));
		this.drawTexturedQuadFit(20, 20, 20, 20, 0);
		GL11.glPopMatrix();
		GL11.glPopMatrix();

	}
}

 

public static void drawTexturedQuadFit(double x, double y, double width, double height, double zLevel)
{
	Tessellator tessellator = Tessellator.instance;
	tessellator.setColorOpaque(255, 255, 255);
	tessellator.startDrawingQuads();
	tessellator.setColorOpaque(255, 255, 255);
	tessellator.addVertexWithUV(x + 0, y + height, zLevel, 0, 1);
	tessellator.addVertexWithUV(x + width, y + height, zLevel, 1, 1);
	tessellator.addVertexWithUV(x + width, y + 0, zLevel, 1, 0);
	tessellator.addVertexWithUV(x + 0, y + 0, zLevel, 0, 0);
	tessellator.setColorOpaque(255, 255, 255);
	tessellator.draw();
}

 

Posted

System.out.println("Drawing Rect");

 

can you see this in your logs ?

 

if not that mean its a event register problem

if yes it mean your problem is related to your matrix configuration, ill help you figure out the correct matrix if that's the case

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

-hydroflame, author of the forge revolution-

Posted

System.out.println("Drawing Rect");

 

can you see this in your logs ?

 

if not that mean its a event register problem

if yes it mean your problem is related to your matrix configuration, ill help you figure out the correct matrix if that's the case

Yup it prints, so its a 'matrix' problem

Posted

ok, it might take a couple of post, but its going to be fixed in the end

 

original code

public void renderCavemanHealthBar(RenderLivingEvent.Specials.Pre event)
{
	mc = mc.getMinecraft();
	GuiIngame gui = mc.ingameGUI;
	if(event.entity instanceof AC_EntityCaveman)
	{

		System.out.println("Drawing Rect");
		Tessellator tessellator = Tessellator.instance;

		EntityClientPlayerMP player = mc.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, 1.0F, 0.0F);
		GL11.glPushMatrix();

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

		mc.func_110434_K().func_110577_a(new ResourceLocation(Strings.MOD_ID, "/textures/gui/temperature_bar.png"));
		this.drawTexturedQuadFit(20, 20, 20, 20, 0);
		GL11.glPopMatrix();
		GL11.glPopMatrix();

	}
}

well simplify thsi a little and grow from there

 

first thing were gonna do is make SURE we are drawing something, so screw the location of it, lets just make sure its rendering

 

 

public void renderCavemanHealthBar(RenderLivingEvent.Specials.Pre event)
{
	mc = mc.getMinecraft();

		GL11.glPushMatrix();
		GL11.glRotatef(System.nanoTime()/10000000f, 0.0F, 1.0F, 0.0F);//this will make the image rotate, might be too fast or too slow, just add /remove zeros if that the case

		mc.func_110434_K().func_110577_a(new ResourceLocation(Strings.MOD_ID, "/textures/gui/temperature_bar.png"));
		this.drawTexturedQuadFit(-1, -1, 2, 2, 0);//this was a bit big and kinof far away from the entity (the 2 first variable are x, y so technicly you were rendering the image 20 block away in x and 20 block away in y
		GL11.glPopMatrix();

}

 

 

go in 3rd person, you should see something turning above your head

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

-hydroflame, author of the forge revolution-

Posted
its not above my head though

is it only off in Y or is it off in XZ too ?

 

in any case lets re-add the translation to the caveman entity

 

public void renderCavemanHealthBar(RenderLivingEvent.Specials.Pre event)
{
	mc = mc.getMinecraft();

		GL11.glPushMatrix();

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));
// btw if you look mathematicly at that its
//int a = 5;
//int b = 2;
diffX = a+(b-a) = a+b-a = b 
// since you're not using the partialTick yet you could simply use the event.entity.posX-player.posX and the effect would be the same
GL11.glTranslated(diffX, diffY, diffZ);//translate to the position of the caveman
		GL11.glRotatef(System.nanoTime()/10000000f, 0.0F, 1.0F, 0.0F);

		mc.func_110434_K().func_110577_a(new ResourceLocation(Strings.MOD_ID, "/textures/gui/temperature_bar.png"));
		this.drawTexturedQuadFit(-1, -1, 2, 2, 0);
		GL11.glPopMatrix();

}

 

also later i suggest you take a look at my texture guide (go on the wiki and search "hydroflame guide to texture") because the way you are creating your ResourceLocation is bad

 

anyway, with this code the image should generally be near the caveman and should be rotating

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

-hydroflame, author of the forge revolution-

Posted

this is just an idea, but do you have a special renderer for your caveman? because if yes you should probably do that there since you have control over it. RenderLivingEvent is for very general things or stuff you cannot normally do because you dont want to touch the source code (in your first thread you refer to another thread, in that one he wanted to render stuff over Villagers  which is a vanilla class and that is why he needed a event for it, in my profile picture i use a RenderLivingEvent too because i dont want to modify vanilla code)

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

-hydroflame, author of the forge revolution-

Posted

"is it only off in Y or is it off in XZ too ?" Y

"you are creating your ResourceLocation is bad" Why is it bad?

I copied your code but added a check to see if it was the caveman and it didnt render. So I removed that check and the bar was still rotating at the same y

 

Heres the code

@ForgeSubscribe
public void renderCavemanHealthBar(RenderLivingEvent.Specials.Pre event)
{
	mc = mc.getMinecraft();
	if(event.entity instanceof AC_EntityCaveman)
	{
		GL11.glPushMatrix();

		double diffX = (event.entity.prevPosX + (event.entity.posX - event.entity.prevPosX)) - (mc.thePlayer.prevPosX + (mc.thePlayer.posX - mc.thePlayer.prevPosX));
		double diffY = (event.entity.prevPosY + (event.entity.posY - event.entity.prevPosY)) - (mc.thePlayer.prevPosY + (mc.thePlayer.posY - mc.thePlayer.prevPosY));
		double diffZ = (event.entity.prevPosZ + (event.entity.posZ - event.entity.prevPosZ)) - (mc.thePlayer.prevPosZ + (mc.thePlayer.posZ - mc.thePlayer.prevPosZ));
		//btw if you look mathematicly at that its
		//int a = 5;
		//int b = 2;
		//	diffX = a+(b-a) = a+b-a = b 
		//since you're not using the partialTick yet you could simply use the event.entity.posX-player.posX and the effect would be the same
		GL11.glTranslated(diffX, diffY, diffZ);//translate to the position of the caveman
		GL11.glRotatef(System.nanoTime() / 10000000f, 0.0F, 1.0F, 0.0F);

		mc.func_110434_K().func_110577_a(new ResourceLocation(Strings.MOD_ID, "/textures/gui/temperature_bar.png"));
		this.drawTexturedQuadFit(- 1, - 1, 2, 2, 0);
		GL11.glPopMatrix();
	}
}

 

@ Your latest reply, I do have a rendercavemen, but what method would I put it in?

Posted
"you are creating your ResourceLocation is bad" Why is it bad?

jsut look at my guide later, no big deal but still...

 

I copied your code but added a check to see if it was the caveman and it didnt render. So I removed that check and the bar was still rotating at the same y

most likely becasue since you removed the caveman check the player you are is also taken into account now so you are renderered with the thing

 

@ Your latest reply, I do have a rendercavemen, but what method would I put it in?

the main one, or maybe maker a smaller that the main render method would call to keep thing clean

example of a generic entity renderer

@Override

public void doRender(Entity entity, double x, double y, double z, float rot, float partialTick)

    {

        GL11.glPushMatrix();

        GL11.glTranslated(x, y, z);

//maybe more transformation

        Minecraft.getMinecraft().renderEngine.func_110577_a(ForgeRevCommonProxy.blankTexture);

        model.render();

        renderTag(entity);

        GL11.glPopMatrix();

    }

 

 

public void renderTag(Entity entity){

//some move/rotate before

//bind the texture

this.drawTexturedQuadFit(-1, -1, 2, 2, 0);

}

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

-hydroflame, author of the forge revolution-

Posted
Hm well ive started to do it in here now, lets just continue in there and I can move it later if need by. So what next?

ok but letting you know that it is a bad programming habit...

 

 

well you said that the quad was only rendering above your head (or inside you, wtv:P) not above the caveman (or inside him)

 

what we need to do now is try to figure out a way to configure the openGL matrix at the location of the entity

 

when you begin the method renderCavemanHealthBar 0, 0, 0 is considered the position of steve eyes

 

double diffX = (event.entity.prevPosX + (event.entity.posX - event.entity.prevPosX)) - (mc.thePlayer.prevPosX + (mc.thePlayer.posX - mc.thePlayer.prevPosX));
		double diffY = (event.entity.prevPosY + (event.entity.posY - event.entity.prevPosY)) - (mc.thePlayer.prevPosY + (mc.thePlayer.posY - mc.thePlayer.prevPosY));
		double diffZ = (event.entity.prevPosZ + (event.entity.posZ - event.entity.prevPosZ)) - (mc.thePlayer.prevPosZ + (mc.thePlayer.posZ - mc.thePlayer.prevPosZ));
		GL11.glTranslated(diffX, diffY, diffZ);//translate to the position of the caveman

these lines are suppose to translate the 0, 0, 0 to the location of the caveman. but basicly it should be translated by "the difference in position between the player and the entity"  try getting very close to the caveman to see if the panel doesnt emerge from somewhere. is the caveman really big meaning it could be tottally inside it ? (and you wouldnt be able to see it)

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

-hydroflame, author of the forge revolution-

Posted

ah, then all you have to do now is increase the height

and use the proper orientation (so that the image always faces the player)

 

@ForgeSubscribe

public void renderCavemanHealthBar(RenderLivingEvent.Specials.Pre event)

{

mc = mc.getMinecraft();

if(event.entity instanceof AC_EntityCaveman)

{

GL11.glPushMatrix();

 

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

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

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

GL11.glTranslated(diffX, diffY, diffZ);

//GL11.glRotatef(System.nanoTime() / 10000000f, 0.0F, 1.0F, 0.0F); no more of use

GL11.glTranslated(0, 5, 0);//could be 6, 7, 10, 2000, youll have to find the god value yourself

//i highly doubt 2000 is even a good value btw

//its approximatelly the same height as your entity, and a little more

GL11.glRotatef(180.0F - event.entityPlayer.renderYawOffset, 0.0F, 1.0F, 0.0F);//this line should make it always face the player, or always away from the player depending on which direction your plane is facing, experiment with it

mc.func_110434_K().func_110577_a(new ResourceLocation(Strings.MOD_ID, "/textures/gui/temperature_bar.png"));

this.drawTexturedQuadFit(- 1, - 1, 2, 2, 0);

GL11.glPopMatrix();

}

}

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

-hydroflame, author of the forge revolution-

Posted

Ok ive got it how i want it. Now you said I could colour it ? What id like is it to be coloured in green which would be its total health then when the health goes down some of the green should be replaced with red depending on how much damage was taken.

Posted

ok well first, the method i gave you, youll need to change it, remove every setColorxxx

public static void drawTexturedQuadFit(double x, double y, double width, double height, double zLevel)

{

Tessellator tessellator = Tessellator.instance;

//tessellator.setColorOpaque(255, 255, 255);

tessellator.startDrawingQuads();

//tessellator.setColorOpaque(255, 255, 255);

tessellator.addVertexWithUV(x + 0, y + height, zLevel, 0, 1);

tessellator.addVertexWithUV(x + width, y + height, zLevel, 1, 1);

tessellator.addVertexWithUV(x + width, y + 0, zLevel, 1, 0);

tessellator.addVertexWithUV(x + 0, y + 0, zLevel, 0, 0);

//tessellator.setColorOpaque(255, 255, 255);

tessellator.draw();

}

because this will force the quad to be white

 

 

then when the health goes down some of the green should be replaced with red depending on how much damage was taken.

by some of the green you mean something like

[g][g][g][g][g][r][r][r]

*lose life*

[g][g][g][g][r][r][r][r]

 

if thats the case you will need to render a lot of quad, openGL can draw as many quad as you want but it wont subseparate them

but basicly to set a color for the quad use

Tessellator.instance.setColorOpaque(R, B, G); //example setColorOpaque(255, 0, 0); for red

and then if you want to render multiple quad (one for each bar of health), somethign like:

 

pseudo code

for(int i =0; i < caveman.getMaxHealth(); i++){
if caveman.getHealth() > i
render a green quad
else render a red quad
move one unit to the left/right (so that all quads are not one over the other)
}

 

 

 

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

-hydroflame, author of the forge revolution-

Posted

I tried it but nothing renders, heres my code

@ForgeSubscribe
public void renderCavemanHealthBar(RenderLivingEvent.Specials.Pre event)
{
	mc = mc.getMinecraft();
	if(event.entity instanceof AC_EntityCaveman)
	{
		GL11.glPushMatrix();

		double diffX = (event.entity.prevPosX + (event.entity.posX - event.entity.prevPosX)) - (mc.thePlayer.prevPosX + (mc.thePlayer.posX - mc.thePlayer.prevPosX));
		double diffY = (event.entity.prevPosY + (event.entity.posY - event.entity.prevPosY)) - (mc.thePlayer.prevPosY + (mc.thePlayer.posY - mc.thePlayer.prevPosY));
		double diffZ = (event.entity.prevPosZ + (event.entity.posZ - event.entity.prevPosZ)) - (mc.thePlayer.prevPosZ + (mc.thePlayer.posZ - mc.thePlayer.prevPosZ));
		GL11.glTranslated(diffX, diffY, diffZ);//translate to the position of the caveman
		//GL11.glRotatef(System.nanoTime() / 10000000f, 0.0F, 1.0F, 0.0F); no more of use
		GL11.glTranslated(0.45, 3.5, 0);//could be 6, 7, 10, 2000, youll have to find the god value yourself
		//i highly doubt 2000 is even a good value btw
		//its approximatelly the same height as your entity, and a little more
		GL11.glRotatef(200.0F - event.entity.renderYawOffset, 0.0F, 1.0F, 0.0F);//this line should make it always face the player, or always away from the player depending on which direction your plane is facing, experiment with it

		mc.func_110434_K().func_110577_a(new ResourceLocation(Strings.MOD_ID, "/textures/gui/health_bar.png"));
		this.drawTexturedQuadFit(- 1, - 1, 2, 2, 0);
		GL11.glPopMatrix();
	}
}

public static void drawTexturedQuadFit(double x, double y, double width, double height, double zLevel)
{
	caveman = caveman.getCaveman();
	Tessellator tessellator = Tessellator.instance;
	if(caveman != null)
	{
		for(int i = 0; i < caveman.func_110138_aP(); i++)
		{
			if(caveman.func_110138_aP() > i)
			{
				tessellator.startDrawingQuads();
				tessellator.setColorOpaque(0, 255, 0);
				tessellator.addVertexWithUV(x + 0, y + height, zLevel, 0, 1);
				tessellator.addVertexWithUV(x + width, y + height, zLevel, 1, 1);
				tessellator.addVertexWithUV(x + width, y + 0, zLevel, 1, 0);
				tessellator.addVertexWithUV(x + 0, y + 0, zLevel, 0, 0);
				tessellator.setColorOpaque(0, 255, 0);
				tessellator.draw();
			}
			else
			{
				tessellator.startDrawingQuads();
				tessellator.setColorOpaque(255, 0, 0);
				tessellator.addVertexWithUV(x + 0, y + height, zLevel, 0, 1);
				tessellator.addVertexWithUV(x + width, y + height, zLevel, 1, 1);
				tessellator.addVertexWithUV(x + width, y + 0, zLevel, 1, 0);
				tessellator.addVertexWithUV(x + 0, y + 0, zLevel, 0, 0);
				tessellator.setColorOpaque(255, 0, 0);
				tessellator.draw();
			}
		}
	}
}

Posted
GL11.glRotatef(200.0F - event.entity.renderYawOffset, 0.0F, 1.0F, 0.0F);

depending on the orientation its possible the quad you render is facing away from you , opengl only render 1 side of each quad you ask him to

 

try thsi

GL11.glRotatef(event.entity.renderYawOffset, 0.0F, 1.0F, 0.0F);

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

-hydroflame, author of the forge revolution-

Posted

well then change the rotate line to teh old rotate with the System.nanoTime, itll render while turning

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

-hydroflame, author of the forge revolution-

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.