Jump to content

[Help needed] Updating Entity textures


Recommended Posts

Hey, I have been trying to figure out how to do this for hours, but no luck. I could really do with some help, so I am hoping that putting my problem here might yield some solutions :)


My Mod: An item that when you right click a mob/player, you can choose a new texture for them.


I am using:

public boolean itemInteractionForEntity(ItemStack par1ItemStack, EntityPlayer Player, EntityLivingBase Target){}

in my item class to target the entity.


(I also have a JFileChooser set up, and working correctly, to select a file path which I can then pass into RecourseLocation.)



[*]I have a targeted EntityLivingBase

[*]I have a texture file path

how can I apply the new texture to the target ?



  • If it is too difficult to make this work for all entities, then it can just be for players.
  • It only needs to update on the players screen, not the target. So, if it is used in SMP and I try to change the skin of a different player, it should only change it in my view and NOT theirs.


Thanks for taking the time to read this and I hope somebody can help me out a little :S

Thanks in advance,




EDIT: I am not sure how much help my code will be, but if you need it for whatever reason, here it is:



public boolean itemInteractionForEntity(ItemStack par1ItemStack, EntityPlayer Player, EntityLivingBase Target){


Minecraft mc= Minecraft.getMinecraft();


//File Chooser

JFrame frame = new JFrame("Skin Tool");

File skinFile = new File ("C:\\Users\\Sam Humby\\Desktop\\SamalotPlays\\Graphics\\Skins");

JFileChooser chooser = new JFileChooser(skinFile);

int result = chooser.showOpenDialog(frame);

if (result == JFileChooser.APPROVE_OPTION) {

File selectedFile = chooser.getSelectedFile();

System.out.println("Selected file: " + selectedFile.getAbsolutePath());

ResourceLocation location = new ResourceLocation(selectedFile.getAbsolutePath()); 



return false;




note: this is a private/personal mod that wont be published, which is why the directories are static.


Link to comment
Share on other sites

Well, the association of the texture with the entity happens in the renderer class.  For example RenderCow class sets the cowTextures ResourceLocation to be ResourceLocation("textures/entity/cow/cow.png").


The problems are that:

a) each render class is different and they don't all have consistent fields or methods for the textures.

b) the texture resource location field and methods are private and protected respectively.


So I think your best bet is to change the renderer mapping by editing the RenderManager.inistance.entityRenderMap directly to replace the renderers with custom renderers.  The safe way to do this is with the rendering registry.  I just tried it out and it works pretty well, but it does mean you need to make a custom renderer class for each texture you want to associate:


You need to put something like this in your client proxy class.

	    RenderingRegistry.registerEntityRenderingHandler(EntityCow.class, new RenderCowMagicBeans(new ModelCow(), 0.7F));


In this case, I made a RenderCowMagicBeans class that looks like this:

public class RenderCowMagicBeans extends RenderLiving

private ResourceLocation cowMagicBeansTexture;

 * @param parModelBase
 * @param parShadowSize
public RenderCowMagicBeans(ModelBase parModelBase, float parShadowSize) 
	super(parModelBase, parShadowSize);

    protected void setEntityTexture()
        cowMagicBeansTexture = new ResourceLocation(MagicBeans.MODID+":textures/entities/cow_magic_beans.png");

    protected ResourceLocation getEntityTexture(Entity par1Entity)
        return cowMagicBeansTexture;


The new texture I pointed to was used for all entity cows.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

EDIT: Fixed it :) I now have a custom render class for the Pig.


Now my biggest issue is working out how to use this static render class from a non-static item class :S


I think what you would do is create a public field (or maybe multiple fields or an array depending on how many entities and textures can be affected) in your mod's main class.  for example you can have a ResourceLocation field for your texturePigCurrent and textureCowCurrent, etc.


Then in your item class you just update this field.  And in the render class you would just reference that field.


so the item doesn't directly do the rendering, but basically updates a public mod field to point to new resource location which is then used by the render class. Get the idea?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.

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.


  • Create New...

Important Information

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