Hi, so I'm having some problems when trying to implement an attack animation for my entity. I've even went through the IrongGolem's entity and model class to try and find answers ending up using a portion of that exact code on mine but, unfortunatly, it doesn't seem to work either. The problem that I'm having is not that the entity isn't animating when attacking, the problem is that all the entities animate in sync when one does. Basicly when one instance of my entity attacks all the the entities play the attack animation at the same time. Please help, I've looked through every tutorial and forum I could find but I still can't find any answers to my problem. Any sugestion helps. Thanks you for your time
Entity Code:
protected int attackTicks;
public EntityTRex(World worldIn) {
super(worldIn);
this.experienceValue = 5;
this.setSize(2.8F, 4.4F);
ambientSounds.add(SoundsHandler.ENTITY_TREX_AMBIENT1);
ambientSounds.add(SoundsHandler.ENTITY_TREX_AMBIENT2);
ambientSounds.add(SoundsHandler.ENTITY_TREX_AMBIENT3);
}
@Override
protected void initEntityAI() {
this.tasks.addTask(1, new EntityAISwimming(this));
this.tasks.addTask(2, new EntityAIWanderAvoidWater(this, 1.0D));
this.tasks.addTask(3, new EntityAIWatchClosest(this, EntityPlayer.class, 10.0F));
this.tasks.addTask(4, new EntityAILookIdle(this));
this.tasks.addTask(0, new EntityAIAttackMelee(this, 1.0D, false));
this.tasks.addTask(0, new EntityAIMoveTowardsRestriction(this, 1.0D));
this.tasks.addTask(0, new EntityAIMoveTowardsTarget(this, 1.0D, 50.0F));
this.targetTasks.addTask(0, new EntityAIHurtByTarget(this, false, new Class[0]));
this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, EntityTRex.class, true));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityPlayer.class, true));
this.targetTasks.addTask(2, new EntityAINearestAttackableTarget(this, EntityVillager.class, true));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityCow.class, true));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntitySheep.class, true));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityPig.class, true));
this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityHorse.class, true));
}
@Override
protected void applyEntityAttributes() {
super.applyEntityAttributes();
this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(20.0D);
this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(60.0D);
this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.453D);
this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(8.0D);
}
public static void registerFixesGuardian(DataFixer fixer) {
EntityLiving.registerFixesMob(fixer, EntityGuardian.class);
}
protected void collideWithEntity(Entity entityIn) {
if (entityIn instanceof IMob && !(entityIn instanceof EntityCreeper) && this.getRNG().nextInt(20) == 0) {
this.setAttackTarget((EntityLivingBase)entityIn);
}
super.collideWithEntity(entityIn);
}
public static void registerFixesTRex(DataFixer fixer) {
EntityLiving.registerFixesMob(fixer, EntityTRex.class);
}
public void onLivingUpdate() {
super.onLivingUpdate();
if (this.attackTicks > 0) {
--this.attackTicks;
}
if (this.motionX * this.motionX + this.motionZ * this.motionZ > 2.500000277905201E-7D && this.rand.nextInt(5) == 0) {
int i = MathHelper.floor(this.posX);
int j = MathHelper.floor(this.posY - 0.20000000298023224D);
int k = MathHelper.floor(this.posZ);
IBlockState iblockstate = this.world.getBlockState(new BlockPos(i, j, k));
if (iblockstate.getMaterial() != Material.AIR)
{
this.world.spawnParticle(EnumParticleTypes.BLOCK_CRACK, this.posX + ((double)this.rand.nextFloat() - 0.5D) * (double)this.width, this.getEntityBoundingBox().minY + 0.1D, this.posZ + ((double)this.rand.nextFloat() - 0.5D) * (double)this.width, 4.0D * ((double)this.rand.nextFloat() - 0.5D), 0.5D, ((double)this.rand.nextFloat() - 0.5D) * 4.0D, Block.getStateId(iblockstate));
}
}
}
public boolean attackEntityAsMob(Entity entityIn) {
this.attackTicks = 20;
this.world.setEntityState(this, (byte)8);
boolean flag = entityIn.attackEntityFrom(DamageSource.causeMobDamage(this), (float)(10 + this.rand.nextInt(15)));
if (flag) {
entityIn.motionY += 0.3500000059604645D;
}
return flag;
}
@SideOnly(Side.CLIENT)
public void handleStatusUpdate(byte id) {
if (id == {
this.attackTicks = 20;
} else {
super.handleStatusUpdate(id);
}
}
@SideOnly(Side.CLIENT)
public int getAttackTicks() {
return this.attackTicks;
}
Model Code:
@SideOnly(Side.CLIENT)
public class ModelTRex extends ZyExAnimations {
//...
public ModelTRex() {
//...
}
@Override
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
this.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
head.render(f5);
middlebody.render(f5);
rightleg.render(f5);
leftleg.render(f5);
rightarm.render(f5);
leftarm.render(f5);
tail.render(f5);
}
public void setRotationAngle(ModelRenderer modelRenderer, float x, float y, float z) {
modelRenderer.rotateAngleX = x;
modelRenderer.rotateAngleY = y;
modelRenderer.rotateAngleZ = z;
}
@Override
public void setRotationAngles(float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw,
float headPitch, float scaleFactor, Entity entityIn) {
this.rightleg.rotateAngleX = MathHelper.cos(limbSwing * 0.332F + (float)Math.PI) * 0.3F * limbSwingAmount;
this.leftleg.rotateAngleX = MathHelper.cos(limbSwing * 0.332F) * 0.3F * limbSwingAmount;
this.head.rotateAngleY = netHeadYaw * 0.017453292F;
this.head.rotateAngleX = headPitch * 0.017453292F;
}
public void setLivingAnimations(EntityLivingBase entitylivingbaseIn, float limbSwing, float limbSwingAmount, float partialTickTime) {
EntityTRex entityTrex = (EntityTRex)entitylivingbaseIn;
int i = entityTrex.getAttackTicks();
if (i > 0) {
// Attack Animation
}
}
}