示例#1
0
  @Override
  protected void attackEntity(Entity entity, float damage) {
    // Prevent attacks during death.
    if (this.getHealth() <= 0.0F) {
      return;
    }

    super.attackEntity(entity, damage);

    double distance = RadixMath.getDistanceToEntity(this, entity);

    if (distance > 3.0F) {
      setAttackPath(entity);
    } else {
      final EntityLivingBase living = (EntityLivingBase) entity;

      // The tank spider can poison its targets.
      if (spiderType == EnumSpiderType.TANK) {
        PotionEffect poison = new PotionEffect(Potion.poison.id, Time.SECOND * 5 * getLevel());
        EntityLivingBase entityLiving = (EntityLivingBase) entity;

        if (entityLiving.isPotionApplicable(poison)
            && !entityLiving.isPotionActive(Potion.poison)) {
          entityLiving.addPotionEffect(poison);
        }
      }

      entity.attackEntityFrom(DamageSource.causeMobDamage(this), getAttackDamage());
    }

    if (onGround && distance < 3.0F) {
      final double dX = entity.posX - posX;
      final double dY = entity.posZ - posZ;
      final float f2 = MathHelper.sqrt_double(dX * dX + dY * dY);
      motionX = dX / f2 * 0.5D * 0.8D + motionX * 0.2D;
      motionZ = dY / f2 * 0.5D * 0.8D + motionZ * 0.2D;
      motionY = 0.4D;
    }
  }