Jump to content

Recommended Posts

Posted

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

 

 

Posted

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

		}
	}

 

 

Posted

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

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.