Jump to content

[solved]Getting a certain part of the player skin


nexusrightsi

Recommended Posts

Hey all, so I'm working on custom races but to have some differences between each player i want the models face texture to actually be the players skin face.

Although I have no clue on how to get this done, so could someone please point me in the right direction? I know there is a way to get the players skin although I don't think there is a method/event to fetch certain parts?

Link to comment
Share on other sites

I think that, because you want the texture to be from a specific player and not Steve, you need to use a TESR (preferably a FastTESR) and render stuff with the tesselator. If you use a FastTESR and not the normal one, you have to be careful to not change any GL states.

Link to comment
Share on other sites

I think that, because you want the texture to be from a specific player and not Steve, you need to use a TESR (preferably a FastTESR) and render stuff with the tesselator. If you use a FastTESR and not the normal one, you have to be careful to not change any GL states.

What? He's working with Entities, not Tile-Entities. You cannot even attach a TESR to a regular entity, as far as I know, not to speak of, entities already have access to the Tessellator & VertexBuffer, through their renderers (RenderLiving, here).

 

I'd have 2 textures: 1 for the body, which all entities would use.

During PlayerLoggedInEvent, get the player's skin (there should be a couple threads already in this forum how to, believe I saw a thread about it a week or two ago). Because all "faces" are in the same area for every player, you should be able to "cut-out"* () his face, and use that as texture #2 for your entity.

 

*Very likely will require some pure java ImageIO techniques.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

Thank you all for the fast replies, I'll have a look into the ImageIO and do some research on it. I'll post an update on the outcome and if successful i'll post my solution here for future reference. (also if this post comes up double, i have no idea what happend to the first one cuz apparently it didn't came through for me.)

Link to comment
Share on other sites

@Matryoshika he didn't state anywhere that he is using entities and because he said "model" I first assumed he meant json models.

 

Also, there is no need for image io. There is a way (I unfortunately don't know how it exactly works) to retrieve the skin's TextureAtlasSprite with the help of the player's GameProfile. This can then be used by the tesselator by binding TextureMap.TEXTURE_MAP_BLOCKS and then getting the interpolated uv's. This would replace the image io stuff but will need some math. Just be aware that the values passed to TextureAtlasSprite#getInterpolatedU() are out of 16, meaning that incrementing the passes value by 1 will give you 16 additional pixels from the 256x256 pixel skin texture.

Link to comment
Share on other sites

@Matryoshika he didn't state anywhere that he is using entities and because he said "model" I first assumed he meant json models.

 

Also, there is no need for image io. There is a way (I unfortunately don't know how it exactly works) to retrieve the skin's TextureAtlasSprite with the help of the player's GameProfile. This can then be used by the tesselator by binding TextureMap.TEXTURE_MAP_BLOCKS and then getting the interpolated uv's. This would replace the image io stuff but will need some math. Just be aware that the values passed to TextureAtlasSprite#getInterpolatedU() are out of 16, meaning that incrementing the passes value by 1 will give you 16 additional pixels from the 256x256 pixel skin texture.

 

I actually did state it was for the players, which indicates that I'm using entities but no biggy there. Thats exactly what I did though, I managed to get the players skin by fetching the gameprofile. Now I just need a way to get the face on the original texture, worst thing is: there is hair on the model that will most likely result in an odd texture if i paste the players face on there :P

Link to comment
Share on other sites

When I read "races" I just thought "no idea what that means but maybe I can help nontheless" :). Depending on how you are rendering your model, there might be a way to disable those overlays used for hair and jackets.

 

I'm trying to tessellate the face somewhat infront of the actual models face with addVertexWithUV although it doesn't seem to be appearing at all. Maybe I did something wrong in the tessellator?

 

code:

private void renderFace(EntityPlayer player)
{
	float f2 = interpolateRotation(player.prevRenderYawOffset, player.renderYawOffset, 1);
	float f3 = interpolateRotation(player.prevRotationYawHead, player.rotationYawHead, 1);
	float f4;

	GameProfile game = new GameProfile(null, Minecraft.getMinecraft().getSession().getUsername());
        Map map = Minecraft.getMinecraft().func_152342_ad().func_152788_a(game);
        ResourceLocation playerTex;
        if (map.containsKey(Type.SKIN)) 
        {
        	playerTex = Minecraft.getMinecraft().func_152342_ad().func_152792_a((MinecraftProfileTexture) map.get(Type.SKIN),Type.SKIN);
        	
        	GL11.glPushMatrix();

		f2 = interpolateRotation(player.prevRenderYawOffset, player.renderYawOffset, 0.5F);
		f4 = MathHelper.wrapAngleTo180_float(f3 - f2);

		if (f4 < -85.0F)
		{
			f4 = -85.0F;
		}
		if (f4 >= 85.0F)
		{
			f4 = 85.0F;
		}
		f2 = f3 - f4;
		if (f4 * f4 > 2500.0F)
		{
			f2 += f4 * 0.2F;
		}

		float modelYOffset = -1.625F;
        	
    		GL11.glEnable(GL11.GL_BLEND);
    		GL11.glDisable(GL11.GL_LIGHTING);
    		GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    		GL11.glRotatef(f2+90F, 0F, -2.0F, 0F);
    		GL11.glTranslatef(-1.25F, 0.25F, 0.60F); //GL11.glTranslatef(-1.0F, -0.0F, 0.70F);
    		GL11.glRotatef(90F, 1.0F, 0.0F, 0.0F);
    		GL11.glRotatef(90F, 0.0F, 0.0F, 1.0F);
    		GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);

    		float textureWidth = 1F/64;//256
    		float textureHeight = 1F/32F;
    		Minecraft.getMinecraft().renderEngine.bindTexture(playerTex);
    		
    		Tessellator t = Tessellator.instance;
    		t.startDrawingQuads();
    		
    		t.addVertexWithUV(1, 0, -1, 16 * textureWidth, 16 * textureHeight);
    		t.addVertexWithUV(1, 1, -1, 16 * textureWidth, 9 * textureHeight);
    		t.addVertexWithUV(1, 1, 1, 9 * textureWidth, 9 * textureHeight);
    		t.addVertexWithUV(1, 0, 1, 9 * textureWidth, 16 * textureHeight);

    		t.draw();
    		GL11.glDisable(GL11.GL_BLEND);
    		GL11.glEnable(GL11.GL_LIGHTING);
    		GL11.glPopMatrix();
        } 
}

Link to comment
Share on other sites

So, i've figured out what the issue is. It seems to be that "if (map.containsKey(Type.SKIN))" always returns false because when I removed this check and changed the texture to an already existing texture in my resources it worked perfectly. I have no idea why this keeps returning false though, I tested it both in dev environment and in a regular minecraft environment.

Link to comment
Share on other sites

Alright, I've fixed it right now. So I removed

 private void renderFace(EntityPlayer player)
{
	float f2 = interpolateRotation(player.prevRenderYawOffset, player.renderYawOffset, 1);
	float f3 = interpolateRotation(player.prevRotationYawHead, player.rotationYawHead, 1);
	float f4;

	GameProfile game = new GameProfile(null, Minecraft.getMinecraft().getSession().getUsername());
        Map map = Minecraft.getMinecraft().func_152342_ad().func_152788_a(game);
        ResourceLocation playerTex;
        if (map.containsKey(Type.SKIN)) 
        {
        	playerTex = Minecraft.getMinecraft().func_152342_ad().func_152792_a((MinecraftProfileTexture) map.get(Type.SKIN),Type.SKIN);

 

and changed that part to this:

private void renderFace(EntityPlayer player)
{
	AbstractClientPlayer p = (AbstractClientPlayer)player;
	ResourceLocation skin = p.getLocationSkin();

 

I also removed the interpolateRotations since it was pretty much a duplicate causing extra rotation, because the player render event actually does the rotations and calls the renderface method too. Weirdest thing is for some reason it didn't moan about the abstractplayer field being static... which it did at first.

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.