I have created a new EntityLiving that is basically an NPC and when I click on it, it talks. The texture works, the animations I don't know (It has no movement), the right click works and the egg spawn too the only problem is when I go far from the entity, it "disappears" or if I'm near it, it "disappears" and if I look the entity again it comes back.
My customEntity class
public class CustomEntity extends EntityLiving {
private boolean persistenceRequired = true;
public CustomEntity(World worldIn) {
super(worldIn);
setEntityInvulnerable(true);
setHealth(100F);
}
public void writeEntityToNBT(NBTTagCompound compound) {
super.writeEntityToNBT(compound);
compound.setBoolean("PersistenceRequired", this.persistenceRequired);
}
public void readEntityFromNBT(NBTTagCompound compound) {
super.readEntityFromNBT(compound);
this.persistenceRequired = compound.getBoolean("PersistenceRequired");
}
@Override
protected boolean processInteract(EntityPlayer player, EnumHand hand) {
Random r = new Random();
World worldIn = player.getEntityWorld();
int phrases = r.nextInt(3);
if (worldIn.isRemote) {
switch (phrases) {
case 0:
Main.message("&dHello &c" + player.getName() + " how are you?", player);
break;
case 1:
Main.message("&aHello &c" + player.getName() + " Can you help me?", player);
break;
case 2:
Main.message("&bHello &c" + player.getName() + "&b! I forgot where is my house", player);
break;
}
}
return true;
}
@Override
protected void despawnEntity() {
if (this.persistenceRequired) {
this.idleTime = 0;
}
}
}
My customentity render class
public class RenderCustomEntity extends RenderLiving<CustomEntity> {
public static final ResourceLocation TEXTURE = new ResourceLocation(
Reference.MODID + ":textures/entity/customentity.png");
public RenderCustomEntity(RenderManager rendermanagerIn) {
super(rendermanagerIn, new ModelCustomEntity(), 0.6F);
}
protected ResourceLocation getEntityTexture(CustomEntity entity) {
return TEXTURE;
}
@Override
protected void applyRotations(CustomEntity entityLiving, float p_77043_2_, float rotationYaw,
float partialTicks) {
super.applyRotations(entityLiving, p_77043_2_, rotationYaw, partialTicks);
}
}
and my cutom entity model class (Made with tabula mod)
public class ModelMCDolaldCashier extends ModelBase {
public ModelRenderer field_178736_x;
public ModelRenderer field_178734_a;
public ModelRenderer field_178731_d;
public ModelRenderer field_178732_b;
public ModelRenderer field_178720_f;
public ModelRenderer field_178733_c;
public ModelRenderer field_178723_h;
public ModelRenderer field_178721_j;
public ModelRenderer field_78116_c;
public ModelRenderer field_78115_e;
public ModelRenderer field_178724_i;
public ModelRenderer field_178722_k;
public ModelMCDolaldCashier() {
this.textureWidth = 64;
this.textureHeight = 32;
this.field_178731_d = new ModelRenderer(this, 0, 16);
this.field_178731_d.setRotationPoint(-1.9F, 12.0F, 0.0F);
this.field_178731_d.addBox(-2.0F, 0.0F, -2.0F, 4, 12, 4, 0.25F);
this.field_178723_h = new ModelRenderer(this, 40, 16);
this.field_178723_h.setRotationPoint(-5.0F, 2.0F, 0.0F);
this.field_178723_h.addBox(-3.0F, -2.0F, -2.0F, 4, 12, 4, 0.0F);
this.field_178732_b = new ModelRenderer(this, 40, 32);
this.field_178732_b.setRotationPoint(-5.0F, 2.0F, 0.0F);
this.field_178732_b.addBox(-3.0F, -2.0F, -2.0F, 4, 12, 4, 0.25F);
this.field_178722_k = new ModelRenderer(this, 0, 16);
this.field_178722_k.setRotationPoint(1.9F, 12.0F, 0.0F);
this.field_178722_k.addBox(-2.0F, 0.0F, -2.0F, 4, 12, 4, 0.0F);
this.field_178721_j = new ModelRenderer(this, 0, 16);
this.field_178721_j.setRotationPoint(-1.899999976158142F, 12.0F, 0.0F);
this.field_178721_j.addBox(-2.0F, 0.0F, -2.0F, 4, 12, 4, 0.0F);
this.field_178720_f = new ModelRenderer(this, 32, 0);
this.field_178720_f.setRotationPoint(0.0F, 0.0F, 0.0F);
this.field_178720_f.addBox(-4.0F, -8.0F, -4.0F, 8, 8, 8, 0.5F);
this.field_178736_x = new ModelRenderer(this, 24, 0);
this.field_178736_x.setRotationPoint(0.0F, 0.0F, 0.0F);
this.field_178736_x.addBox(-3.0F, -6.0F, -1.0F, 6, 6, 1, 0.0F);
this.field_78116_c = new ModelRenderer(this, 0, 0);
this.field_78116_c.setRotationPoint(0.0F, 0.0F, 0.0F);
this.field_78116_c.addBox(-4.0F, -8.0F, -4.0F, 8, 8, 8, 0.0F);
this.field_178734_a = new ModelRenderer(this, 48, 48);
this.field_178734_a.setRotationPoint(5.0F, 2.0F, 0.0F);
this.field_178734_a.addBox(-1.0F, -2.0F, -2.0F, 4, 12, 4, 0.25F);
this.field_178724_i = new ModelRenderer(this, 32, 48);
this.field_178724_i.setRotationPoint(5.0F, 2.0F, 0.0F);
this.field_178724_i.addBox(-1.0F, -2.0F, -2.0F, 4, 12, 4, 0.0F);
this.field_178733_c = new ModelRenderer(this, 0, 48);
this.field_178733_c.setRotationPoint(1.899999976158142F, 12.0F, 0.0F);
this.field_178733_c.addBox(-2.0F, 0.0F, -2.0F, 4, 12, 4, 0.25F);
this.field_78115_e = new ModelRenderer(this, 16, 16);
this.field_78115_e.setRotationPoint(0.0F, 0.0F, 0.0F);
this.field_78115_e.addBox(-4.0F, 0.0F, -2.0F, 8, 12, 4, 0.0F);
}
@Override
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
this.field_178731_d.render(f5);
this.field_178723_h.render(f5);
this.field_178732_b.render(f5);
this.field_178722_k.render(f5);
this.field_178721_j.render(f5);
this.field_178720_f.render(f5);
this.field_178736_x.render(f5);
this.field_78116_c.render(f5);
this.field_178734_a.render(f5);
this.field_178724_i.render(f5);
this.field_178733_c.render(f5);
this.field_78115_e.render(f5);
}
/**
* This is a helper function from Tabula to set the rotation of model parts
*/
public void setRotateAngle(ModelRenderer modelRenderer, float x, float y, float z) {
modelRenderer.rotateAngleX = x;
modelRenderer.rotateAngleY = y;
modelRenderer.rotateAngleZ = z;
}
}