Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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;
   }

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.