This wiki is a read-only version of the Stardew Valley Wiki. The official editable wiki maintained by ConcernedApe can be found at stardewvalleywiki.com

Changes

Jump to: navigation, search

Modding:Migrate to SMAPI 3.0

1,409 bytes added, 06:32, 2 April 2019
Changes: + mods loaded earlier
==Changes==
===Mods are loaded earlier===
Mods were previously loaded right before the first <tt>UpdateTicking</tt> event, which is too late for some changes like intercepting core assets. SMAPI 3.0 loads them much earlier, before the game is fully initialised. '''Do not depend on game fields like <tt>Game1.objectInformation</tt> having a valid value in your <tt>Entry</tt> method!''' You can use the <tt>GameLaunched</tt> event for that instead. See [[Modding:Modder Guide/APIs/Mod structure#Mod entry]] for more info.
 
For example, let's say you have code like this:
<source lang="c#">
public override void Entry(IModHelper helper)
{
this.Config = helper.ReadConfig<ModConfig>();
 
CommunityCenter communityCenter = (CommunityCenter)Game1.getLocationFromName("CommunityCenter");
this.VaultRoomID = communityCenter.getAreaNumberFromName("Vault");
}
</source>
 
That code will fail in SMAPI 3.0, because no locations are loaded yet. This code could be rewritten like this:
<source lang="c#">
public override void Entry(IModHelper helper)
{
this.Config = helper.ReadConfig<ModConfig>();
 
helper.Events.GameLoop.GameLaunched += this.OnGameLaunched;
}
 
private void OnGameLaunched(object sender, GameLaunchedEventArgs args)
{
CommunityCenter communityCenter = (CommunityCenter)Game1.getLocationFromName("CommunityCenter");
this.VaultRoomID = communityCenter.getAreaNumberFromName("Vault");
}
</source>
 
===API changes===
{| class="wikitable"
Protected, translators
5,421
edits

Navigation menu