Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10] Change player model (and skin/texture)


Androm
 Share

Recommended Posts

Hello there,

maybe it's a stupid question but how do you change the player model? I searched in goggle and later I recompiled a mod which change the player model. But nothing helped.

I want that the player is rendered with a special model and a special texture (all the time).

My code:

 

package de.MhytRPG.www.events;

import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraftforge.client.event.RenderPlayerEvent;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import de.MhytRPG.www.entitys.Dwarf;
import de.MhytRPG.www.mobs.Modells.ModelDwarf;
import de.MhytRPG.www.utils.PlayerEntity;

public class OnRenderPlayerEvents {

@SubscribeEvent
public void onRenderPlayerPre(RenderPlayerEvent.Pre pre) {
	int type = 0;
                //not used now. Later it will return the type of the model as int --> example: 1 = ModelFirst, 2 = ModelSecond
	if(PlayerEntity.getPlayerEntity(pre.entityPlayer) != null) {
		type = PlayerEntity.getPlayerEntity(pre.entityPlayer);
	}
                //not used now
	switch (type) {
	case 0:
		break;
	case 1:

		break;
	case 2:

		break;
	case 3:

		break;
	case 4:

		break;
	case 5:

		break;
	case 6:

		break;
	default:
		break;
	}
                //I tried that before but it doesn´t work (no crash, but no other model)
	//pre.renderer.setRenderPassModel(new ModelDwarf());
                //That changed the model, but the skin wasn´t changed and there were no rotations(my fault?) That´s what I got from decompiling a mod (Custom Player Models[beta])
	//ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, pre.renderer, new ModelDwarf(), new String[] { "mainModel", "field_77045_g" });
}

@SubscribeEvent
public void onRenderPlayerPost(RenderPlayerEvent.Post post) {

}

}

 

I think there is an easy way to do it and I am just too stupid. Thanks for your help!

Link to comment
Share on other sites

//I tried that before but it doesn´t work (no crash, but no other model)

//pre.renderer.setRenderPassModel(new ModelDwarf());

                //That changed the model, but the skin wasn´t changed and there were no rotations(my fault?) That´s what I got from decompiling a mod (Custom Player Models[beta])

//ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, pre.renderer, new ModelDwarf(), new String[] { "mainModel", "field_77045_g" });

 

I tried something but ObsucationReflectionHandler... sets the Main model of all players.

Link to comment
Share on other sites

I don't think that would be right. Every player has the chance to choose one from six models to play.So on a server where there are different models they will be rendered the same way. But I want that you can see different models(later handled by packets because informations are always saved on server).

Link to comment
Share on other sites

Do you mean that:

 

package de.MhytRPG.www.events;

import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraftforge.client.event.RenderPlayerEvent;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import de.MhytRPG.www.entitys.Dwarf;
import de.MhytRPG.www.mobs.Modells.ModelDwarf;
import de.MhytRPG.www.mobs.Modells.ModelElfFemale;
import de.MhytRPG.www.mobs.Modells.ModelElfMale;
import de.MhytRPG.www.mobs.Modells.ModelOrk;
import de.MhytRPG.www.utils.PlayerEntity;

public class OnRenderPlayerEvents {

@SubscribeEvent
public void onRenderPlayerPre(RenderPlayerEvent.Pre pre) {
	int type = 0;
	if(PlayerEntity.getPlayerEntity(pre.entityPlayer) != null) {
		type = PlayerEntity.getPlayerEntity(pre.entityPlayer);
	}
	switch (type) {
	case 0:
		ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, pre.renderer, new ModelDwarfMale(), new String[] { "mainModel", "field_77045_g" });
		break;
	case 1:
		ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, pre.renderer, new ModelDwarfFemale(), new String[] { "mainModel", "field_77045_g" });
		break;
	case 2:
		ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, pre.renderer, new ModelOrkMale(), new String[] { "mainModel", "field_77045_g" });
		break;
	case 3:
		ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, pre.renderer, new ModelOrkFemale(), new String[] { "mainModel", "field_77045_g" });
		break;
	case 4:
		ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, pre.renderer, new ModelElfMale(), new String[] { "mainModel", "field_77045_g" });
		break;
	case 5:
		ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, pre.renderer, new ModelElfFemale(), new String[] { "mainModel", "field_77045_g" });
		break;
	default:
		break;
	}
	//ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, pre.renderer, new ModelDwarf(), new String[] { "mainModel", "field_77045_g" });
}

@SubscribeEvent
public void onRenderPlayerPost(RenderPlayerEvent.Post post) {
	ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, post.renderer, new ModelBiped(), new String[] { "mainModel", "field_77045_g" });
}

}

 

So you can see three players on server and they will have different models (just need to change the steve texture)?

 

Link to comment
Share on other sites

The model change but I there isn´t the right texture. Forge tries to set the steve texture on my custom model. I know I forgot it. The problem is i don´t know how to change the texture. Maybe too with ObfuscationReflectionHelper or is there an easy method? Thanks for your help! (I know I can optimize my code, but please don´t say it)

 

package de.MhytRPG.www.events;

import net.minecraft.client.model.ModelBase;
import net.minecraftforge.client.event.RenderPlayerEvent;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import de.MhytRPG.www.mobs.Modells.ModelDwarfFemale;
import de.MhytRPG.www.mobs.Modells.ModelDwarfMale;
import de.MhytRPG.www.mobs.Modells.ModelElfFemale;
import de.MhytRPG.www.mobs.Modells.ModelElfMale;
import de.MhytRPG.www.mobs.Modells.ModelOrkFemale;
import de.MhytRPG.www.mobs.Modells.ModelOrkMale;
import de.MhytRPG.www.utils.PlayerEntity;

public class OnRenderPlayerEvents {

private ModelBase value;

@SubscribeEvent
public void onRenderPlayerPre(RenderPlayerEvent.Pre pre) {
	value = ObfuscationReflectionHelper.getPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, pre.renderer, new String[] { "mainModel", "field_77045_g" });
	int type = 0;
	if(PlayerEntity.getPlayerEntity(pre.entityPlayer) != null) {
		type = PlayerEntity.getPlayerEntity(pre.entityPlayer);
	}
	switch (type) {
	case 0:
		ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, pre.renderer, new ModelDwarfMale(), new String[] { "mainModel", "field_77045_g" });
		break;
	case 1:
		ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, pre.renderer, new ModelDwarfFemale(), new String[] { "mainModel", "field_77045_g" });
		break;
	case 2:
		ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, pre.renderer, new ModelOrkMale(), new String[] { "mainModel", "field_77045_g" });
		break;
	case 3:
		ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, pre.renderer, new ModelOrkFemale(), new String[] { "mainModel", "field_77045_g" });
		break;
	case 4:
		ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, pre.renderer, new ModelElfMale(), new String[] { "mainModel", "field_77045_g" });
		break;
	case 5:
		ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, pre.renderer, new ModelElfFemale(), new String[] { "mainModel", "field_77045_g" });
		break;
	default:
		break;
	}
}

@SubscribeEvent
public void onRenderPlayerPost(RenderPlayerEvent.Post post) {
	ObfuscationReflectionHelper.setPrivateValue(net.minecraft.client.renderer.entity.RendererLivingEntity.class, post.renderer, value, new String[] { "mainModel", "field_77045_g" });
}

}

 

Link to comment
Share on other sites

You'll have to do the rendering yourself (probably through a custom RenderPlayer instance or something like that) if you want to change the texture.

And yes, I will say that your code has performance problems. This code runs multiple times per frame. Looking up multiple fields every time (unnecessarily!) is a waste.

Link to comment
Share on other sites

The code in the RenderPlayer.class is big, I don´t think i need it at all. Do I have to use openGL to draw and handle the rendering or are there some finished mehods in forge? (like for entitys you just give the model and the resourcelocation and voila the entity is rendered right)? I hope you understand me.

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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.