From 286c2d244949f4eee62e2de440938d2d8ae3ce76 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 11 Nov 2022 20:55:24 -0500 Subject: pass multiplayer into asset propagator to avoid reflection --- src/SMAPI/Metadata/CoreAssetPropagator.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/SMAPI/Metadata') diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index d94fe2ae..037e4573 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -40,6 +40,9 @@ namespace StardewModdingAPI.Metadata /// Writes messages to the console. private readonly IMonitor Monitor; + /// The multiplayer instance whose map cache to update. + private readonly Multiplayer Multiplayer; + /// Simplifies access to private game code. private readonly Reflector Reflection; @@ -70,13 +73,15 @@ namespace StardewModdingAPI.Metadata /// The main content manager through which to reload assets. /// An internal content manager used only for asset propagation. /// Writes messages to the console. + /// The multiplayer instance whose map cache to update. /// Simplifies access to private code. /// Parse a raw asset name. - public CoreAssetPropagator(LocalizedContentManager mainContent, GameContentManagerForAssetPropagation disposableContent, IMonitor monitor, Reflector reflection, Func parseAssetName) + public CoreAssetPropagator(LocalizedContentManager mainContent, GameContentManagerForAssetPropagation disposableContent, IMonitor monitor, Multiplayer multiplayer, Reflector reflection, Func parseAssetName) { this.MainContentManager = mainContent; this.DisposableContentManager = disposableContent; this.Monitor = monitor; + this.Multiplayer = multiplayer; this.Reflection = reflection; this.ParseAssetName = parseAssetName; } @@ -1166,12 +1171,9 @@ namespace StardewModdingAPI.Metadata GameLocation location = locationInfo.Location; Vector2? playerPos = Game1.player?.Position; - // clear cachedMultiplayerMaps so Asset Propegation works on farmhands and Map edits can be applied after an initial load - if (!Game1.IsMasterGame) - { - var multiplayer = this.Reflection.GetField(typeof(Game1), "multiplayer").GetValue(); - multiplayer.cachedMultiplayerMaps.Remove(locationInfo.Location.NameOrUniqueName); - } + // clear multiplayer cache for farmhands + if (!Context.IsMainPlayer) + this.Multiplayer.cachedMultiplayerMaps.Remove(location.NameOrUniqueName); // reload map location.interiorDoors.Clear(); // prevent errors when doors try to update tiles which no longer exist -- cgit