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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffc3fe22b60, pid=15228, tid=5140 # # JRE version: OpenJDK Runtime Environment Microsoft-8035246 (17.0.8+7) (build 17.0.8+7-LTS) # Java VM: OpenJDK 64-Bit Server VM Microsoft-8035246 (17.0.8+7-LTS, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64) # Problematic frame: # C [atio6axx.dll+0x192b60] # # No core dump will be written. Minidumps are not enabled by default on client versions of Windows # # If you would like to submit a bug report, please visit: # https://aka.ms/minecraftjavacrashes # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug i have no idea why please help
    • Considering the financial revolution sparked by cryptocurrencies like Bitcoin, the digital era has opened up a plethora of opportunities. But this exciting new world also comes with a terrible reality: in the harsh, brutal blockchain environment, there's always a danger you could lose your precious digital assets. Services like ADWARE RECOVERY SPECIALIST are not merely recovery agents in this case; they are crypto lifelines, and my own experience attests to their vital importance. I had an amazing time exploring the world of Bitcoin on my own; it was exciting to be in a completely new place and to see the possibility of independent money. However, a careless mistake of choosing the incorrect platform for my investment sent me into total despair. It seemed as though my digital lifeblood, Bitcoin, had been devoured by the blockchain's vicious maw. Overwhelmed with hope, I began a frantic quest for solutions, looking up any clue of assistance on the internet. I discovered  ADWARE RECOVERY SPECIALIST at that point.  Initially, I was filled with misgivings, but their unwavering professionalism and clear communication offered me a glimpse of hope. I set them the very impossible task of locating my missing fortune. The ADWARE RECOVERY SPECIALIST team of professionals meticulously penetrated the labyrinthine depths of the blockchain with the aid of cutting-edge technology and years of honed experience, treating my case with the utmost care and respect and keeping me informed at every turn. I had never encountered anything like the recuperation process. The days of confusing technical jargon and excruciatingly long wait times were over. And then the miraculous happened. My Bitcoin miraculously reappeared in my wallet, coming safe and sound from the digital void in an almost amazing length of time. Integrating  ADWARE RECOVERY SPECIALIST into your Bitcoin recovery process is not as magical as waving a wand, but it sure feels like it with the seamless and effective tools it offers. By following best practices, training your staff, and learning from successful case studies, you can optimize your Bitcoin recovery efforts and stay ahead of potential risks. The future outlook for Bitcoin recovery with ADWARE RECOVERY SPECIALIST looks promising, providing users with the confidence and tools they need to navigate the ever-evolving landscape of digital assets. It was a very happy moment that showcased the ADWARE RECOVERY SPECIALIST team's remarkable talent and dedication. However, my experience serves more purposes than just self-interest; it serves as a sobering reminder of the expanding demand for dependable and trustworthy bitcoin recovery services, such as ADWARE online recovery.
    • Quick-Books is great with regards to coordinating your monetary data. You can decide to live talk with a specialist at Quick-Books to get the answer for your questions. You will actually want to get to the talk going to the landing page and call us +1855-210-1428.
    • Update: I managed to make the item not disappear after crafting, but it doesn't remove any durability. import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.Enchantments; import net.minecraft.enchantment.UnbreakingEnchantment; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class NuggetHammer extends Item { private boolean damage; public NuggetHammer(Properties p_i48487_1_) { super(p_i48487_1_); } @Override public int getMaxDamage(ItemStack stack) { return 54 - 1; } public boolean isBarVisible(ItemStack stack) { return false; } @Override public ItemStack getContainerItem(ItemStack stack) { ItemStack copy = stack.copy(); copy.setCount(1); if (!this.damage) return copy; int unbreaking = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.UNBREAKING, stack); for (int i = 0; i < unbreaking; i++) { if (UnbreakingEnchantment.shouldIgnoreDurabilityDrop(stack, unbreaking, random)) return copy; } copy.setDamageValue(stack.getDamageValue() + 1); if (copy.getDamageValue() > stack.getMaxDamage()) return ItemStack.EMPTY; return copy; } }  
  • Topics

×
×
  • Create New...

Important Information

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