Posted February 6, 201411 yr I want my mob to perform animations when it is attacking somebody else. Well, for compare IronGolem does it when he attacks. I've tried to use Golem's part of code, but that not works on my mob. So, here is the code, i used from the Golem: ModelMob public void setLivingAnimations(EntityLiving par1EntityLiving, float par2, float par3, float par4) { EntityHeadcrabZombie entityheadcrabzombie = (EntityHeadcrabZombie)par1EntityLiving; int i = entityheadcrabzombie.getAttackTimer(); if (i > 0) { this.rightArm.rotateAngleX = -2.0F + 1.5F * this.func_78172_a((float)i - par4, 10.0F); this.leftArm.rotateAngleX = -2.0F + 1.5F * this.func_78172_a((float)i - par4, 10.0F); } } private float func_78172_a(float par1, float par2) { return (Math.abs(par1 % par2 - par2 * 0.5F) - par2 * 0.25F) / (par2 * 0.25F); } EntityMob public boolean attackEntityAsMob(Entity par1Entity) { this.attackTimer = 10; this.worldObj.setEntityState(this, (byte)4); boolean flag = par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), 7 + this.rand.nextInt(15)); if (flag) { par1Entity.motionY += 0.4000000059604645D; } this.playSound("hzombie.hzo_attack", 1.0F, 1.0F); return flag; } public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) { super.writeEntityToNBT(par1NBTTagCompound); } public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) { super.readEntityFromNBT(par1NBTTagCompound); } protected float getSoundVolume() { return 0.5F; } protected boolean canDespawn() // respawn after kill on the same spot { return false; } public void onLivingUpdate() { super.onLivingUpdate(); if (this.attackTimer > 0) { --this.attackTimer; } if (this.motionX * this.motionX + this.motionZ * this.motionZ > 2.500000277905201E-7D && this.rand.nextInt(5) == 0) { int i = MathHelper.floor_double(this.posX); int j = MathHelper.floor_double(this.posY - 0.20000000298023224D - (double)this.yOffset); int k = MathHelper.floor_double(this.posZ); int l = this.worldObj.getBlockId(i, j, k); if (l > 0) { this.worldObj.spawnParticle("tilecrack_" + l + "_" + this.worldObj.getBlockMetadata(i, j, k), this.posX + ((double)this.rand.nextFloat() - 0.5D) * (double)this.width, this.boundingBox.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); } } } @SideOnly(Side.CLIENT) public void handleHealthUpdate(byte par1) { if (par1 == 4) { this.attackTimer = 10; } else { super.handleHealthUpdate(par1); } } @SideOnly(Side.CLIENT) public int getAttackTimer() { return this.attackTimer; }
February 7, 201411 yr Author Anybody? What's strange in my problem, that nobody dont know what to do...
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.