Jump to content

Implementing Rendering Same Entity with Different Textures (Like Villagers)


Recommended Posts

Posted

Hello,

I would like to add a mechanic in my mod where I can render the same entity with different textures based on RNG (Random Number Generation). The concept is similar to Villagers in minecraft and their professions. Here is my code currently (not knowing that the constructor for RenderWanderingPlayer is only called once, not everytime the entity spawned)

 

package xyz.gatya.itmulti.render;

import java.util.Random;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelPlayer;
import net.minecraft.client.renderer.entity.RenderLiving;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.util.ResourceLocation;
import xyz.gatya.itmulti.entity.EntityInformation;
import xyz.gatya.itmulti.entity.EntityWanderingPlayer;
import xyz.gatya.itmulti.util.ModInformation;

public class RenderWanderingPlayer extends RenderLiving<EntityWanderingPlayer> {
	
	private static final ResourceLocation TEXTURES = new ResourceLocation(
			ModInformation.MOD_ID + 
			":textures/entity/" + 
			EntityInformation.WANDERING_NPC_SKINS[(int) (Math.random() * EntityInformation.WANDERING_NPC_SKINS.length + 1)] + ".png"
		);
	
	public RenderWanderingPlayer(RenderManager rendermanagerIn) {
		super(rendermanagerIn, new ModelPlayer(0.0F, false), 0.3F);
	}

	@Override
	protected ResourceLocation getEntityTexture(EntityWanderingPlayer entity) {
		return TEXTURES;
	}

}

 

Code :

EntityInformation -> Contains some information of the entity i.e id, available skins for the entity and etc.

WANDERING_NPC_SKINS -> Array of strings of possible skins

 

How do I get it to work? The code is just for demonstration

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.