Jump to content

[1.7.10] How to Change Player Model and Texture


Thornack

Recommended Posts

Hi Everyone,

 

I have figured out how to change the players model using the ObfuscationReflectionHelper but i have not been able to figure out a way to change the model and texture. Using the method directly below (spoiler 1) the default player texture is overlaid onto the model you choose. Also this method is currently inefficient since I believe it is called multiple times a frame but I am not positive about this.

 

 

public class EventChangePlayerModel {

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onRenderPlayerPre(RenderPlayerEvent.Pre pre) {

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

 

 

 

What I want it to do is something more like cancel the player render event and then render my own model in its place using my custom renderer so that I can have custom textures. But I have run into a problem. I know how to cancel the player event but dont know how to add my own renderer in its place after cancelling so that the player model is replaced with the custom one I choose.

 

 

public class EventAChangePlayerModel {

	@SubscribeEvent(priority = EventPriority.HIGHEST)
	public void onRenderPlayerPre(RenderPlayerEvent.Pre pre) {

		if (pre.isCancelable()) {
			pre.setCanceled(true); // this stops the player from rendering

//This is the part im not sure about I have a custom entity with a custom model and this entity appears in game perfectly when I spawn it. I want to make the player model/texture to be the same as //the entity I choose. The following did not work:
			addCustomRenderer(EntityMonster.class, new ModelMonsterr(), "Monster.png", 0.4f);
			return;
		}
	}


public void addCustomRenderer(Class<? extends Entity> entityClass, ModelBase model, String textureFileName, float shadowRadius ){
	RenderingRegistry.registerEntityRenderingHandler(entityClass, new RenderCustomModel(model, textureFileName, shadowRadius));
}
}

 

 

 

Im not sure what the problem is since the method addCustomRenderer works perfectly when I use it in my ClientProxy to render my mobs when they are spawned in game. In my ClientProxy I use the following method(s) to register my entities  and this works perfectly where my mobs show up normal and rendered correctly whether i use my custom spawning event or using a monster egg.

 

I have also tried to call my renderer directly in place of the addCustomRenderer Method using -> RenderCustomModel() render = new  RenderCustomModel(new ModelMonster(), "Monster.png", 1f); but this didnt work either. Am I missing something stupid I have been at this for a while.

The ClientProxy Methods

 

 


public void registerRenderInformation(){ //this overrides a method in CommonProxy to add the renderers to the mod where my mobs all spawn correctly and render correctly 

//Register mobile Entities
	addCustomRenderer(EntityMonster.class, new ModelMonsterr(), "Monster.png", 0.4f);
}

public void addCustomRenderer(Class<? extends Entity> entityClass, ModelBase model, String textureFileName, float shadowRadius ){
	RenderingRegistry.registerEntityRenderingHandler(entityClass, new RenderCustomModel(model, textureFileName, shadowRadius));
}

 

 

 

my entity renderer class (works) [note**] I removed a function that I use to render custom entity information cause I dont wish to share that and it shouldnt be relevant to my problem

 

 

@SideOnly(Side.CLIENT)
public class RenderCustomModel extends RenderLiving
{
private ResourceLocation texture;

public RenderCustomModel(ModelBase model, String textureName, float shadowRadius)
{
	super(model, shadowRadius);
	this.texture = new ResourceLocation("custommod:textures/mob/" + textureName);

}

public void doRender(Entity entity, double x, double y, double z, float par8, float par9){
	//this.RenderSelf((EntityLiving)par1Entity, par2, par4, par6, par8, par9);
	super.doRender(entity, x, y, z, par8, par9);
	}

/**
 * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
 */
protected ResourceLocation getEntityTexture(Entity entity){
	return this.texture;
}
}

 

 

Link to comment
Share on other sites

I have solved this problem but I do have a question. How do you access the players height and width and the bounding box and the camera zoom. I need to alter these fields to work with my model. I have been trying to figure that out for a while and cant seem to figure it out.

 

My solution (posted below) involves cancelling the default player render and then rendering my own model. The model shows up with the correct texture. I had to change my renderer to extend RendererLivingEntity otherwise if I extend RenderLiving I got a crash Im not sure why. Anyway, this is the solution I came up with below. I do have a question as I have very little experience with changing the player - will my solution work in multiplayer to display the model to other players? Or do I have to do something special to achieve this? Currently I dont have a way to test for this multiplayer behaviour so That is why I am asking.

 

My Renderer

 

 

@SideOnly(Side.CLIENT)
public class RenderCustomModelAsPlayer extends RendererLivingEntity //I get a crash if I try to extend RenderLiving so must extend RendererLivingEntity for some reason
{
private ResourceLocation texture;
    

    public RenderCustomModelAsPlayer(ModelBase model, String textureName, float shadowRadius)
    {
       super(model, shadowRadius);
       this.renderManager = RenderManager.instance;
       this.texture = new ResourceLocation("custommod:textures/mob/" + textureName);
    }

    @Override
    protected ResourceLocation getEntityTexture(Entity par1Entity)
    {
        return this.texture;
    }
//Call the doRender function directly inside EventChangePlayerModel class in the  onRenderPlayerPre() method to render the model you want
    @Override
    public void doRender(EntityLivingBase entity, double x, double y, double z, float par8, float par9)
    {
    	 	super.doRender(entity, x, y, z, par8, par9);
    }
      

   
}

 

 

 

ChangePlayerModel Event

 

 

public class EventChangePlayerModel {

      private final Render renderCustomModel = new RenderCustomModelAsPlayer(new ModelMonsterr(), "Monster.png", 1.0f);
	@SubscribeEvent
	public void onRenderPlayerPre(RenderPlayerEvent.Pre pre) {
			pre.setCanceled(true); // this stops the player from rendering
			float modelYOffset = -1.625F;
			renderCustomModel.doRender(pre.entity, 0F, modelYOffset, 0F, 0F, 0.0625F);

		}
	}

 

 

Link to comment
Share on other sites

I was wondering if anyone knows how I could access the players height and width of the bounding box and the player camera zoom (i guess its position). I need to alter these fields to work with my model (I need to zoom out the camera (change its position to be farther backwards) and I need to change the height of the players bounding/hitbox and I need to change the location of the + target mouse over icon thing to change the "height" at which the model breaks blocks/hits entities etc. If anyone knows anything about this I would appreciate your input

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I create my mod pack,yesterday my mod pack is fine but i add one mod and error. I'm delete this mmod but minecraft is still stop on CONFIG_LOAD then I tried to delete config and restart it but again. If you can pleace help me. https://imgur.com/ngZBzuv
    • game crashes before even opening (log:https://mclo.gs/M8xvX7c)
    • I have created a custom entity that extends "TamableAnimal", but I am wanting to have it spawn in the ocean. I have it spawning right now, but it spawns way too frequently even with weight set to 1. I am guessing it is because it is rolling in the spawn pool of land animals since TameableAnimal extends Animal and is different than WaterAnimal, and since no land animals spawn in the ocean it just fills every inch up with my custom entity. I have followed basic tutorials for spawning entities with Forge, but I feel like I am missing something about how to change what spawn pool this custom entity ends up in. Is it possible to change that or do I need to refactor it to be based off of WaterAnimal to get those spawn? My biome modifier JSON file: { "type": "forge:add_spawns", "biomes": "#minecraft:is_ocean", "spawners": { "type": "darwinsmysticalmounts:water_wyvern", "weight": 20, "minCount": 1, "maxCount": 1 } } My client event: event.register(ModEntityTypes.WATER_WYVERN.get(), SpawnPlacements.Type.NO_RESTRICTIONS, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, WaterWyvernEntity::checkWaterWyvernSpawnRules, SpawnPlacementRegisterEvent.Operation.REPLACE); And the actual custom spawn rule that makes it spawn in the water: public static boolean checkWaterWyvernSpawnRules(EntityType<WaterWyvernEntity> pAnimal, LevelAccessor pLevel, MobSpawnType pSpawnType, BlockPos pPos, RandomSource pRandom) { return pPos.getY() > pLevel.getSeaLevel() - 16 && pLevel.getFluidState(pPos.below()).is(FluidTags.WATER); }  
    • Starting today, I am unable to load my modded minecraft world. Forge crash log initially said it was a specific mod called Doggy Talents, which I disabled. Then it blamed JEI, and when that was disabled it blamed another mod so I assume it's something more than a specific mod. Minecraft launcher log claims "Exit Code 1". Nothing had changed since last night when it was working fine Forge Log: https://pastebin.com/S1GiBGVJ Client Log: https://pastebin.com/aLwuGUNL  
    • I am using AMD, yes. I downloaded the website's drivers and am still having the issue. I also used the Cleanup Utility just in case. 
  • Topics

×
×
  • Create New...

Important Information

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