diff --git a/src/SMAPI/Framework/Content/AssetInfo.cs b/src/SMAPI/Framework/Content/AssetInfo.cs
index c632249d..363fffb3 100644
--- a/src/SMAPI/Framework/Content/AssetInfo.cs
+++ b/src/SMAPI/Framework/Content/AssetInfo.cs
@@ -36,7 +36,12 @@ namespace StardewModdingAPI.Framework.Content
source: SCore.DeprecationManager.GetModFromStack(),
nounPhrase: $"{nameof(IAssetInfo)}.{nameof(IAssetInfo.AssetName)}",
version: "3.14.0",
- severity: DeprecationLevel.Notice
+ severity: DeprecationLevel.Notice,
+ unlessStackIncludes: new[]
+ {
+ $"{typeof(AssetInterceptorChange).FullName}.{nameof(AssetInterceptorChange.CanIntercept)}",
+ $"{typeof(ContentCoordinator).FullName}.{nameof(ContentCoordinator.GetAssetOperations)}"
+ }
);
return this.NameWithoutLocale.Name;
@@ -72,7 +77,12 @@ namespace StardewModdingAPI.Framework.Content
source: SCore.DeprecationManager.GetModFromStack(),
nounPhrase: $"{nameof(IAssetInfo)}.{nameof(IAssetInfo.AssetNameEquals)}",
version: "3.14.0",
- severity: DeprecationLevel.Notice
+ severity: DeprecationLevel.Notice,
+ unlessStackIncludes: new[]
+ {
+ $"{typeof(AssetInterceptorChange).FullName}.{nameof(AssetInterceptorChange.CanIntercept)}",
+ $"{typeof(ContentCoordinator).FullName}.{nameof(ContentCoordinator.GetAssetOperations)}"
+ }
);
diff --git a/src/SMAPI/Framework/Deprecations/DeprecationManager.cs b/src/SMAPI/Framework/Deprecations/DeprecationManager.cs
index 84ce2132..5ca07702 100644
--- a/src/SMAPI/Framework/Deprecations/DeprecationManager.cs
+++ b/src/SMAPI/Framework/Deprecations/DeprecationManager.cs
@@ -56,15 +56,21 @@ namespace StardewModdingAPI.Framework.Deprecations
/// A noun phrase describing what is deprecated.
/// The SMAPI version which deprecated it.
/// How deprecated the code is.
- public void Warn(IModMetadata? source, string nounPhrase, string version, DeprecationLevel severity)
+ /// A list of stack trace substrings which should suppress deprecation warnings if they appear in the stack trace.
+ public void Warn(IModMetadata? source, string nounPhrase, string version, DeprecationLevel severity, string[]? unlessStackIncludes = null)
{
- // ignore if already warned
- if (!this.MarkWarned(source, nounPhrase, version))
+ // skip if already warned
+ string cacheKey = $"{source?.DisplayName ?? ""}::{nounPhrase}::{version}";
+ if (this.LoggedDeprecations.Contains(cacheKey))
return;
- // queue warning
+ // warn if valid
ImmutableStackTrace stack = ImmutableStackTrace.Get(skipFrames: 1);
- this.QueuedWarnings.Add(new DeprecationWarning(source, nounPhrase, version, severity, stack));
+ if (!this.ShouldSuppress(stack, unlessStackIncludes))
+ {
+ this.LoggedDeprecations.Add(cacheKey);
+ this.QueuedWarnings.Add(new DeprecationWarning(source, nounPhrase, version, severity, stack));
+ }
}
/// A placeholder method used to track deprecated code for which a separate warning will be shown.
@@ -117,18 +123,22 @@ namespace StardewModdingAPI.Framework.Deprecations
/*********
** Private methods
*********/
- /// Mark a deprecation warning as already logged.
- /// The mod which used the deprecated code.
- /// A noun phrase describing what is deprecated (e.g. "the Extensions.AsInt32 method").
- /// The SMAPI version which deprecated it.
- /// Returns whether the deprecation was successfully marked as warned. Returns false if it was already marked.
- private bool MarkWarned(IModMetadata? source, string nounPhrase, string version)
+ /// Get whether a deprecation warning should be suppressed.
+ /// The stack trace for which it was raised.
+ /// A list of stack trace substrings which should suppress deprecation warnings if they appear in the stack trace.
+ private bool ShouldSuppress(ImmutableStackTrace stack, string[]? unlessStackIncludes)
{
- string key = $"{source?.DisplayName ?? ""}::{nounPhrase}::{version}";
- if (this.LoggedDeprecations.Contains(key))
- return false;
- this.LoggedDeprecations.Add(key);
- return true;
+ if (unlessStackIncludes?.Any() == true)
+ {
+ string stackTrace = stack.ToString();
+ foreach (string method in unlessStackIncludes)
+ {
+ if (stackTrace.Contains(method))
+ return true;
+ }
+ }
+
+ return false;
}
/// Get the simplest stack trace which shows where in the mod the deprecated code was called from.