Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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!

  • Author

No the RenderPlayerPre event is called. But Ich didn't change something in renderPlayerPost event.

  • Author

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

  • Author

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

  • Author

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)?

 

  • Author

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" });
}

}

 

  • Author

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.

Sorry to disturb you guys, i'm following your discussion since three days ago.

 

I have One question: Is this method to modify the model is nice if you want your mod compatible with others mod who modify the modelPlayer too  ?

(hope that you understand what i mean ;) )

  • Author

Maybe you could use the RenderPlayer API. It will do it compatible with other mods if they use it.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.