Difference between revisions of "Modding:Migrate to SMAPI 3.0"

From Stardew Valley Wiki
Jump to navigation Jump to search
(→‎Major changes: reorder, + Manifest version format)
 
(22 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
←[[Modding:Index|Index]]
 
←[[Modding:Index|Index]]
<div style="border: 1px solid red; background: #FCC; padding: 1em;">'''This is an internal draft page. SMAPI 3.0 is not ready and modders don't need to do anything yet.</div>
 
  
'''This page is for modders. Players: see [[Modding:SMAPI compatibility]] instead.'''
+
{{Modder compatibility header}}
 
+
This page explains how to update your mod code for compatibility with SMAPI 3.0. See also [[Modding:Migrate to Stardew Valley 1.4]].
This page explains how to update your mod code for compatibility with SMAPI 3.0 (release TBD).
 
  
 
==Overview==
 
==Overview==
Line 10: Line 8:
 
[[File:SMAPI compatibility.png|thumb|SMAPI compatibility over time. The SMAPI 2.0 release in October 2017 appears as a small bump. The Stardew Valley 1.3 release in May 2018 appears as a sudden cliff.]]
 
[[File:SMAPI compatibility.png|thumb|SMAPI compatibility over time. The SMAPI 2.0 release in October 2017 appears as a small bump. The Stardew Valley 1.3 release in May 2018 appears as a sudden cliff.]]
  
Events are arguably the most important and most visible part of SMAPI, but they've stayed essentially unchanged since SMAPI 0.40. New events have been added organically since then, but the event system has always been separate from the rest of SMAPI — they're inconsistent, have some weird behaviours (like <tt>MenuEvents.MenuChanged</tt> not being raised when a menu is closed), aren't available through the same helper as every other API, and there are some glaring omissions in the available events.
+
Events are arguably the most important and most visible part of SMAPI, but they've stayed essentially unchanged since SMAPI 0.40. New events have been added organically since then, but the event system has always been separate from the rest of SMAPI — they're inconsistent, have some weird behaviours (like <samp>MenuEvents.MenuChanged</samp> not being raised when a menu is closed), aren't available through the same helper as every other API, and there are some glaring omissions in the available events.
  
 
SMAPI 3.0 is the release that fixes all that. This release...
 
SMAPI 3.0 is the release that fixes all that. This release...
Line 18: Line 16:
 
* Weird behaviours and overlapping events have been eliminated.
 
* Weird behaviours and overlapping events have been eliminated.
 
* Many new events have been added.
 
* Many new events have been added.
* Every event now has relevant event arguments.
+
* Events now have relevant event arguments.
 +
* Each mod now has its own event instances, to support features like mod message targeting.
 +
 
 +
SMAPI 3.0 also adds compatibility with Stardew Valley 1.4, drops all deprecated APIs, and makes a number of other changes listed below.
  
 
===Is this the modapocalypse?===
 
===Is this the modapocalypse?===
Nope. Although this is a major change, significant effort will be undertaken to minimise the impact:
+
Nope. Although this is a major change, significant efforts were undertaken to minimize the impact:
* the old events will be supported for a long time with increasingly prominent warnings in the SMAPI console about their deprecation and removal;
+
* the old events were supported for a long time with increasingly prominent warnings in the SMAPI console about their deprecation and removal;
* pull requests will be submitted to update affected open-source mods;
+
* pull requests were submitted to update affected open-source mods;
* unofficial updates will be created for mods which haven't updated officially by the time SMAPI 3.0 is released;
+
* unofficial updates were created for mods which haven't updated officially by the time SMAPI 3.0 is released;
* the changes will be actively communicated and documented to modders.
+
* the changes were actively communicated and documented to modders.
  
 
In addition, the current target is ''at least'' 95% compatibility for open-source mods before SMAPI 3.0 is released. All of this means that the 3.0 release should have minimal impact on mod compatibility, despite the scope of the changes.
 
In addition, the current target is ''at least'' 95% compatibility for open-source mods before SMAPI 3.0 is released. All of this means that the 3.0 release should have minimal impact on mod compatibility, despite the scope of the changes.
Line 36: Line 37:
 
# You can refer to the following sections on how to replace specific interfaces.
 
# You can refer to the following sections on how to replace specific interfaces.
  
==Major changes==
+
==Changes==
 +
===Mod build package updated===
 +
Update the [https://www.nuget.org/packages/Pathoschild.Stardew.ModBuildConfig mod build package] for compatibility with SMAPI 3.0.
 +
 
 +
===Mods are loaded earlier===
 +
Mods were previously loaded right before the first <samp>UpdateTicking</samp> 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 <samp>Game1.objectInformation</samp> having a valid value in your <samp>Entry</samp> method!''' You can use the <samp>GameLaunched</samp> 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:
 +
<syntaxhighlight lang="c#">
 +
public override void Entry(IModHelper helper)
 +
{
 +
  this.Config = helper.ReadConfig<ModConfig>();
 +
 
 +
  CommunityCenter communityCenter = (CommunityCenter)Game1.getLocationFromName("CommunityCenter");
 +
  this.VaultRoomID = communityCenter.getAreaNumberFromName("Vault");
 +
}
 +
</syntaxhighlight>
 +
 
 +
That code fails in SMAPI 3.0, because no locations are loaded yet. This code could be rewritten like this:
 +
<syntaxhighlight 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");
 +
}
 +
</syntaxhighlight>
 +
 
 
===API changes===
 
===API changes===
 
{| class="wikitable"
 
{| class="wikitable"
Line 45: Line 79:
 
! conversion notes
 
! conversion notes
 
|-
 
|-
| <tt>helper.CreateTransitionalContentPack</tt>
+
| <samp>helper.GetContentPacks</samp>
 +
| →
 +
| <samp>helper.ContentPacks.GetOwned</samp>
 +
| Identical usage.
 +
|-
 +
| <samp>helper.CreateTransitionalContentPack</samp>
 
| →
 
| →
| <tt>helper.CreateTemporaryContentPack</tt>
+
| <samp>helper.ContentPacks.CreateTemporary</samp>
 
| Identical usage. (This was a temporary method for the transition to [[Modding:Content packs|SMAPI content packs]], but a few mods have permanent use cases for it.)
 
| Identical usage. (This was a temporary method for the transition to [[Modding:Content packs|SMAPI content packs]], but a few mods have permanent use cases for it.)
 
|-
 
|-
| <tt>SemanticVersion.Build</tt>
+
| <samp>assetData.AsDictionary&lt;T, T&gt;().Set</samp>
 +
| →
 +
| <samp>assetData.AsDictionary&lt;T, T&gt;().Data</samp>
 +
| The <samp>Set</samp> methods caused a lot of confusion and were of limited usefulness. You can access the dictionary directly using the <samp>Data</samp> field instead.
 +
|-
 +
| <samp>SemanticVersion.Build</samp>
 
| →
 
| →
| <tt>SemanticVersion.PrereleaseTag</tt>
+
| <samp>SemanticVersion.PrereleaseTag</samp>
 
| Identical usage.
 
| Identical usage.
 
|}
 
|}
  
 
===Event changes===
 
===Event changes===
The former events will be removed in SMAPI 3.0. Here's how to convert them to the new events under <tt>this.Helper.Events</tt>. This list only shows equivalent events in SMAPI 3.0; see [[Modding:Modder Guide/APIs/Events|''events'' in the modder guide]] for a full list.
+
The former events are removed in SMAPI 3.0. Here's how to convert them to the new events under <samp>this.Helper.Events</samp>. This list only shows equivalent events in SMAPI 3.0; see [[Modding:Modder Guide/APIs/Events|''events'' in the modder guide]] for a full list.
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 74: Line 118:
 
  |new events = Input.ButtonPressed, Input.ButtonReleased
 
  |new events = Input.ButtonPressed, Input.ButtonReleased
 
  |summary    = Mostly equivalent.
 
  |summary    = Mostly equivalent.
* Remove <tt>e.PlayerIndex</tt> (this was always <tt>PlayerIndex.One</tt>).
+
* Remove <samp>e.PlayerIndex</samp> (this was always <samp>PlayerIndex.One</samp>).
* Change <tt>e.ButtonPressed</tt> to <tt>e.Button</tt>, which is now an [[Modding:Modder Guide/APIs/Utilities#Input|<tt>SButton</tt>]] value.
+
* Change <samp>e.ButtonPressed</samp> to <samp>e.Button</samp>, which is now an [[Modding:Modder Guide/APIs/Utilities#Input|<samp>SButton</samp>]] value.
* Remove <tt>e.Value</tt> for trigger events.
+
* Remove <samp>e.Value</samp> for trigger events.
 
}}
 
}}
 
{{/event
 
{{/event
Line 87: Line 131:
 
  |new events = Input.ButtonPressed, Input.ButtonReleased
 
  |new events = Input.ButtonPressed, Input.ButtonReleased
 
  |summary    = Mostly equivalent.
 
  |summary    = Mostly equivalent.
* Change <tt>e.KeyPressed</tt> to <tt>e.Button</tt>, which is now an [[Modding:Modder Guide/APIs/Utilities#Input|<tt>SButton</tt>]] value.
+
* Change <samp>e.KeyPressed</samp> to <samp>e.Button</samp>, which is now an [[Modding:Modder Guide/APIs/Utilities#Input|<samp>SButton</samp>]] value.
 
}}
 
}}
 
{{/event
 
{{/event
Line 95: Line 139:
 
}}
 
}}
 
{{/event
 
{{/event
  |old events = GameEvents.EighthUpdateTick, GameEvents.FourthUpdateTick, GameEvents.HalfSecondTick, GameEvents.OneSecondTick, GameEvents.QuarterSecondTick, GameEvents.SecondUpdateTick
+
  |old events = GameEvents.EighthUpdateTick, GameEvents.FourthUpdateTick, GameEvents.HalfSecondTick, GameEvents.QuarterSecondTick, GameEvents.SecondUpdateTick
 
  |new events = GameLoop.UpdateTicked
 
  |new events = GameLoop.UpdateTicked
  |summary    = Mostly equivalent. You can match the previous update ticks using <code>e.IsMultipleOf</code> (<tt>SecondUpdateTick</tt> = 2, <tt>FourthUpdateTick</tt> = 4, <tt>EighthUpdateTick</tt> = 8, <tt>QuarterSecondTick</tt> = 15, and <tt>HalfSecondTick</tt> = 30) and <code>e.IsOneSecond</code>.
+
  |summary    = Mostly equivalent. You can use <code>e.IsMultipleOf</code> to choose an update rate (<samp>SecondUpdateTick</samp> = 2, <samp>FourthUpdateTick</samp> = 4, <samp>EighthUpdateTick</samp> = 8, <samp>QuarterSecondTick</samp> = 15, and <samp>HalfSecondTick</samp> = 30).
 
}}
 
}}
 
{{/event
 
{{/event
 
  |old events = GameEvents.FirstUpdateTick
 
  |old events = GameEvents.FirstUpdateTick
 
  |new events = GameLoop.GameLaunched
 
  |new events = GameLoop.GameLaunched
  |summary    = The new event is raised before the first update tick (the old one happened after it). To do something ''after'' the first update tick, use <tt>GameEvents.UpdateTicked</tt> with <tt>if (e.Ticks == 1)</tt>.
+
  |summary    = The new event is raised before the first update tick (the old one happened after it). To do something ''after'' the first update tick, use <samp>GameEvents.UpdateTicked</samp> with <samp>if (e.Ticks == 1)</samp>.
 
}}
 
}}
 
{{/event
 
{{/event
 
  |old events = GameEvents.UpdateTick
 
  |old events = GameEvents.UpdateTick
 
  |new events = GameLoop.UpdateTicked
 
  |new events = GameLoop.UpdateTicked
 +
|summary    = equivalent
 +
}}
 +
{{/event
 +
|old events = GameEvents.OneSecondTick
 +
|new events = GameLoop.OneSecondUpdateTicked
 
  |summary    = equivalent
 
  |summary    = equivalent
 
}}
 
}}
Line 112: Line 161:
 
  |old events = GraphicsEvents.OnPostRenderEvent
 
  |old events = GraphicsEvents.OnPostRenderEvent
 
  |new events = Display.Rendered
 
  |new events = Display.Rendered
  |summary    = Equivalent, except the new event isn't triggered during certain special cutscenes and minigames (e.g. the [[Sebastian#Six Hearts|board game scene]]).
+
  |summary    = Equivalent, except the new event isn't triggered during certain special cutscenes and minigames (''e.g.,'' the [[Sebastian#Six Hearts|board game scene]]).
}}
 
{{/event
 
|old events = GraphicsEvents.OnPostRenderGuiEvent
 
|new events = Display.RenderedActiveMenu
 
|summary    = equivalent
 
 
}}
 
}}
 
{{/event
 
{{/event
Line 153: Line 197:
 
  |new events = Input.ButtonPressed, Input.ButtonReleased
 
  |new events = Input.ButtonPressed, Input.ButtonReleased
 
  |summary    = Mostly equivalent.
 
  |summary    = Mostly equivalent.
* Change <tt>e.IsActionButton</tt> to <tt>e.Button.IsActionButton()</tt>.
+
* Change <samp>e.IsActionButton</samp> to <samp>e.Button.IsActionButton()</samp>.
* Change <tt>e.IsUseToolButton</tt> to <tt>e.Button.IsUseToolButton()</tt>.
+
* Change <samp>e.IsUseToolButton</samp> to <samp>e.Button.IsUseToolButton()</samp>.
* Change <tt>e.SuppressButton</tt> to <tt>this.Helper.Input.Suppress(button)</tt>.
+
* Change <samp>e.SuppressButton</samp> to <samp>this.Helper.Input.Suppress(button)</samp>.
 
}}
 
}}
 
{{/event
 
{{/event
Line 175: Line 219:
 
  |old events = MenuEvents.MenuChanged, MenuEvents.MenuClosed
 
  |old events = MenuEvents.MenuChanged, MenuEvents.MenuClosed
 
  |new events = Display.MenuChanged
 
  |new events = Display.MenuChanged
  |summary    = These caused a lot of confusion (e.g. <tt>MenuEvents.MenuClosed</tt> wasn't called when a menu was closed and immediately replaced), so they've been combined into one event which is called when a menu is opened, closed, or replaced. You can check the <tt>e.OldMenu</tt> and <tt>e.NewMenu</tt> event args to know what the change is (e.g. to match the old <tt>MenuEvents.MenuClosed</tt>, check <code>if (e.NewMenu == null)</code>).
+
  |summary    = These caused a lot of confusion (''e.g.,'' <samp>MenuEvents.MenuClosed</samp> wasn't called when a menu was closed and immediately replaced), so they've been combined into one event which is called when a menu is opened, closed, or replaced. You can check the <samp>e.OldMenu</samp> and <samp>e.NewMenu</samp> event args to know what the change is (''e.g.,'' to match the old <samp>MenuEvents.MenuClosed</samp>, check <code>if (e.NewMenu == null)</code>).
 
}}
 
}}
 
{{/event
 
{{/event
 
  |old events = MineEvents.MineLevelChanged
 
  |old events = MineEvents.MineLevelChanged
  |new events = PlayerEvents.Warped
+
  |new events = Player.Warped
  |summary    = To know whether the player changed mine level, you can check <code>if (e.NewLocation is MineShaft mine)</code>; the new mine level will be <code>mine.mineLevel</code>.
+
  |summary    = Check <code>if (e.NewLocation is MineShaft mine)</code> to detect a mine level change (the new mine level will be <code>mine.mineLevel</code>). Although the new event is still only called for the current player, that may change in a future version; '''make sure to check <samp>e.IsLocalPlayer</samp> if you only want to handle the current player'''.
 
}}
 
}}
 
{{/event
 
{{/event
 
  |old events = MultiplayerEvents.AfterMainBroadcast, MultiplayerEvents.AfterMainSync, MultiplayerEvents.BeforeMainBroadcast, MultiplayerEvents.BeforeMainSync
 
  |old events = MultiplayerEvents.AfterMainBroadcast, MultiplayerEvents.AfterMainSync, MultiplayerEvents.BeforeMainBroadcast, MultiplayerEvents.BeforeMainSync
 
  |new events = none
 
  |new events = none
  |summary    = No known mods use these. If you need them, consider replacing <tt>Game1.multiplayer</tt> with a delegating subclass.
+
  |summary    = No known mods use these. If you need them, consider replacing <samp>Game1.multiplayer</samp> with a delegating subclass.
 
}}
 
}}
 
{{/event
 
{{/event
 
  |old events = PlayerEvents.InventoryChanged
 
  |old events = PlayerEvents.InventoryChanged
 
  |new events = Player.InventoryChanged
 
  |new events = Player.InventoryChanged
  |summary    = Mostly equivalent. The event arguments changed type, but should be straightforward to migrate. Although the new event is still only called for the current player, that will likely change in a future version; '''make sure to check <tt>e.IsLocalPlayer</tt> if you only want to handle the current player'''.
+
  |summary    = Mostly equivalent. The event arguments changed type, but should be straightforward to migrate. Although the new event is still only called for the current player, that may change in a future version; '''make sure to check <samp>e.IsLocalPlayer</samp> if you only want to handle the current player'''.
 
}}
 
}}
 
{{/event
 
{{/event
 
  |old events = PlayerEvents.LeveledUp
 
  |old events = PlayerEvents.LeveledUp
 
  |new events = Player.LevelChanged
 
  |new events = Player.LevelChanged
  |summary    = Mostly equivalent. The event arguments changed type, but should be straightforward to migrate. Although the new event is still only called for the current player, that will likely change in a future version; '''make sure to check <tt>e.IsLocalPlayer</tt> if you only want to handle the current player'''.
+
  |summary    = Mostly equivalent. The event arguments changed type, but should be straightforward to migrate. Although the new event is still only called for the current player, that may change in a future version; '''make sure to check <samp>e.IsLocalPlayer</samp> if you only want to handle the current player'''.
 
}}
 
}}
 
{{/event
 
{{/event
 
  |old events = PlayerEvents.Warped
 
  |old events = PlayerEvents.Warped
 
  |new events = Player.Warped
 
  |new events = Player.Warped
  |summary    = Mostly equivalent. The event arguments changed type, but should be straightforward to migrate. Although the new event is still only called for the current player, that will likely change in a future version; '''make sure to check <tt>e.IsLocalPlayer</tt> if you only want to handle the current player'''.
+
  |summary    = Mostly equivalent. The event arguments changed type, but should be straightforward to migrate. Although the new event is still only called for the current player, that may change in a future version; '''make sure to check <samp>e.IsLocalPlayer</samp> if you only want to handle the current player'''.
 
}}
 
}}
 
{{/event
 
{{/event
Line 245: Line 289:
 
  |old events = TimeEvents.TimeOfDayChanged
 
  |old events = TimeEvents.TimeOfDayChanged
 
  |new events = GameLoop.TimeChanged
 
  |new events = GameLoop.TimeChanged
  |summary    = Mostly equivalent. Change <tt>e.OldInt</tt> and <tt>e.NewInt</tt> to <tt>e.OldTime</tt> and <tt>e.NewTime</tt> respectively.
+
  |summary    = Mostly equivalent. Change <samp>e.OldInt</samp> and <samp>e.NewInt</samp> to <samp>e.OldTime</samp> and <samp>e.NewTime</samp> respectively.
 
}}
 
}}
 
|}
 
|}
  
 
===Manifest version format===
 
===Manifest version format===
The [[Modding:Modder Guide/APIs/Manifest|<tt>manifest.json</tt>]] no longer allows versions in this form:
+
The [[Modding:Modder Guide/APIs/Manifest|<samp>manifest.json</samp>]] no longer allows versions in this form:
<source lang="js">
+
<syntaxhighlight lang="js">
 
"Version": {
 
"Version": {
 
   "MajorVersion": 1,
 
   "MajorVersion": 1,
Line 258: Line 302:
 
   "Build": "beta"
 
   "Build": "beta"
 
}
 
}
</source>
+
</syntaxhighlight>
  
 
Versions should be written in the standard string form instead:
 
Versions should be written in the standard string form instead:
<source lang="js">
+
<syntaxhighlight lang="js">
 
"Version": "1.0.0-beta"
 
"Version": "1.0.0-beta"
</source>
+
</syntaxhighlight>
 +
 
 +
===Version format===
 +
SMAPI no longer omits <code>.0</code> patch numbers when formatting versions. For example, the console now shows SMAPI 3.0.0 instead of 3.0. That's more [https://semver.org/ standard], improves compatibility with external tools, and reduces player confusion.
 +
 
 +
This doesn't affect most mod code. You may need to update your code if you use <samp>ISemanticVersion.ToString()</samp> and compare the output to a hardcoded two-part version string.
  
 
[[Category:Modding]]
 
[[Category:Modding]]

Latest revision as of 05:53, 26 March 2022

Index

This page is for mod authors. Players: see Modding:Mod compatibility instead.

This page explains how to update your mod code for compatibility with SMAPI 3.0. See also Modding:Migrate to Stardew Valley 1.4.

Overview

What's changing?

SMAPI compatibility over time. The SMAPI 2.0 release in October 2017 appears as a small bump. The Stardew Valley 1.3 release in May 2018 appears as a sudden cliff.

Events are arguably the most important and most visible part of SMAPI, but they've stayed essentially unchanged since SMAPI 0.40. New events have been added organically since then, but the event system has always been separate from the rest of SMAPI — they're inconsistent, have some weird behaviours (like MenuEvents.MenuChanged not being raised when a menu is closed), aren't available through the same helper as every other API, and there are some glaring omissions in the available events.

SMAPI 3.0 is the release that fixes all that. This release...

  • Completely rewrites the event engine to make events more efficient and enable events that weren't possible before.
  • Makes events much more consistent: they're now fully compliant with the .NET design guidelines, have predictable and descriptive names, have consistent event handler signatures, and have clear documentation.
  • All events are now accessible through helper.Events, so they're discoverable like any other SMAPI API.
  • Weird behaviours and overlapping events have been eliminated.
  • Many new events have been added.
  • Events now have relevant event arguments.
  • Each mod now has its own event instances, to support features like mod message targeting.

SMAPI 3.0 also adds compatibility with Stardew Valley 1.4, drops all deprecated APIs, and makes a number of other changes listed below.

Is this the modapocalypse?

Nope. Although this is a major change, significant efforts were undertaken to minimize the impact:

  • the old events were supported for a long time with increasingly prominent warnings in the SMAPI console about their deprecation and removal;
  • pull requests were submitted to update affected open-source mods;
  • unofficial updates were created for mods which haven't updated officially by the time SMAPI 3.0 is released;
  • the changes were actively communicated and documented to modders.

In addition, the current target is at least 95% compatibility for open-source mods before SMAPI 3.0 is released. All of this means that the 3.0 release should have minimal impact on mod compatibility, despite the scope of the changes.

How to update your mod

You don't need to comb through your code manually. SMAPI can tell you if you're using a deprecated interface:

  1. Use the latest SMAPI for developers download. This will show deprecation messages in the console:
    Modding - updating deprecated SMAPI code - deprecation warnings.png
  2. When you look at the code, you'll see a deprecation warning with a hint of how to fix it:
    Modding - updating deprecated SMAPI code - deprecation intellisense.png
  3. You can refer to the following sections on how to replace specific interfaces.

Changes

Mod build package updated

Update the mod build package for compatibility with SMAPI 3.0.

Mods are loaded earlier

Mods were previously loaded right before the first UpdateTicking 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 Game1.objectInformation having a valid value in your Entry method! You can use the GameLaunched 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:

public override void Entry(IModHelper helper)
{
   this.Config = helper.ReadConfig<ModConfig>();

   CommunityCenter communityCenter = (CommunityCenter)Game1.getLocationFromName("CommunityCenter");
   this.VaultRoomID = communityCenter.getAreaNumberFromName("Vault");
}

That code fails in SMAPI 3.0, because no locations are loaded yet. This code could be rewritten like this:

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

API changes

old API new API conversion notes
helper.GetContentPacks helper.ContentPacks.GetOwned Identical usage.
helper.CreateTransitionalContentPack helper.ContentPacks.CreateTemporary Identical usage. (This was a temporary method for the transition to SMAPI content packs, but a few mods have permanent use cases for it.)
assetData.AsDictionary<T, T>().Set assetData.AsDictionary<T, T>().Data The Set methods caused a lot of confusion and were of limited usefulness. You can access the dictionary directly using the Data field instead.
SemanticVersion.Build SemanticVersion.PrereleaseTag Identical usage.

Event changes

The former events are removed in SMAPI 3.0. Here's how to convert them to the new events under this.Helper.Events. This list only shows equivalent events in SMAPI 3.0; see events in the modder guide for a full list.

old event new event conversion notes
#ContentEvents.AfterLocaleChanged none Mods very rarely need to handle this, since SMAPI's translation and content APIs do. Since the locale can only change on the title screen, mods that used this can check once the save is loaded instead.
#ControlEvents.ControllerButtonPressed
ControlEvents.ControllerButtonReleased
ControlEvents.ControllerTriggerPressed
ControlEvents.ControllerTriggerReleased
Input.ButtonPressed
Input.ButtonReleased
Mostly equivalent.
  • Remove e.PlayerIndex (this was always PlayerIndex.One).
  • Change e.ButtonPressed to e.Button, which is now an SButton value.
  • Remove e.Value for trigger events.
#ControlEvents.KeyboardChanged Input.ButtonPressed
Input.ButtonReleased
Not directly equivalent; may need to rewrite affected code.
#ControlEvents.KeyPressed
ControlEvents.KeyReleased
Input.ButtonPressed
Input.ButtonReleased
Mostly equivalent.
  • Change e.KeyPressed to e.Button, which is now an SButton value.
#ControlEvents.MouseChanged Input.ButtonPressed
Input.ButtonReleased
Input.CursorMoved
Input.MouseWheelScrolled
Not directly equivalent; may need to rewrite affected code.
#GameEvents.EighthUpdateTick
GameEvents.FourthUpdateTick
GameEvents.HalfSecondTick
GameEvents.QuarterSecondTick
GameEvents.SecondUpdateTick
GameLoop.UpdateTicked Mostly equivalent. You can use e.IsMultipleOf to choose an update rate (SecondUpdateTick = 2, FourthUpdateTick = 4, EighthUpdateTick = 8, QuarterSecondTick = 15, and HalfSecondTick = 30).
#GameEvents.FirstUpdateTick GameLoop.GameLaunched The new event is raised before the first update tick (the old one happened after it). To do something after the first update tick, use GameEvents.UpdateTicked with if (e.Ticks == 1).
#GameEvents.UpdateTick GameLoop.UpdateTicked Equivalent.
#GameEvents.OneSecondTick GameLoop.OneSecondUpdateTicked Equivalent.
#GraphicsEvents.OnPostRenderEvent Display.Rendered Equivalent, except the new event isn't triggered during certain special cutscenes and minigames (e.g., the board game scene).
#GraphicsEvents.OnPostRenderGuiEvent Display.RenderedActiveMenu Equivalent.
#GraphicsEvents.OnPostRenderHudEvent Display.RenderedHud Equivalent.
#GraphicsEvents.OnPreRenderEvent Display.RenderingWorld Equivalent.
#GraphicsEvents.OnPreRenderGuiEvent Display.RenderingActiveMenu Equivalent.
#GraphicsEvents.OnPreRenderHudEvent Display.RenderingHud Equivalent.
#GraphicsEvents.Resize Display.WindowResized Equivalent.
#InputEvents.ButtonPressed
InputEvents.ButtonReleased
Input.ButtonPressed
Input.ButtonReleased
Mostly equivalent.
  • Change e.IsActionButton to e.Button.IsActionButton().
  • Change e.IsUseToolButton to e.Button.IsUseToolButton().
  • Change e.SuppressButton to this.Helper.Input.Suppress(button).
#LocationEvents.BuildingsChanged World.BuildingListChanged Equivalent.
#LocationEvents.LocationsChanged World.LocationListChanged Equivalent.
#LocationEvents.ObjectsChanged World.ObjectListChanged Equivalent.
#MineEvents.MineLevelChanged Player.Warped Check if (e.NewLocation is MineShaft mine) to detect a mine level change (the new mine level will be mine.mineLevel). Although the new event is still only called for the current player, that may change in a future version; make sure to check e.IsLocalPlayer if you only want to handle the current player.
#MultiplayerEvents.AfterMainBroadcast
MultiplayerEvents.AfterMainSync
MultiplayerEvents.BeforeMainBroadcast
MultiplayerEvents.BeforeMainSync
none No known mods use these. If you need them, consider replacing Game1.multiplayer with a delegating subclass.
#PlayerEvents.InventoryChanged Player.InventoryChanged Mostly equivalent. The event arguments changed type, but should be straightforward to migrate. Although the new event is still only called for the current player, that may change in a future version; make sure to check e.IsLocalPlayer if you only want to handle the current player.
#PlayerEvents.LeveledUp Player.LevelChanged Mostly equivalent. The event arguments changed type, but should be straightforward to migrate. Although the new event is still only called for the current player, that may change in a future version; make sure to check e.IsLocalPlayer if you only want to handle the current player.
#PlayerEvents.Warped Player.Warped Mostly equivalent. The event arguments changed type, but should be straightforward to migrate. Although the new event is still only called for the current player, that may change in a future version; make sure to check e.IsLocalPlayer if you only want to handle the current player.
#SaveEvents.AfterCreate GameLoop.SaveCreated Equivalent.
#SaveEvents.AfterLoad GameLoop.SaveLoaded Equivalent.
#SaveEvents.AfterReturnToTitle GameLoop.ReturnedToTitle Equivalent.
#SaveEvents.AfterSave GameLoop.Saved Equivalent.
#SaveEvents.BeforeCreate GameLoop.SaveCreating Equivalent.
#SaveEvents.BeforeSave GameLoop.Saving Equivalent.
#SpecialisedEvents.UnvalidatedUpdateTick Specialised.UnvalidatedUpdateTicked Equivalent.
#TimeEvents.AfterDayStarted GameLoop.DayStarted Equivalent.
#TimeEvents.TimeOfDayChanged GameLoop.TimeChanged Mostly equivalent. Change e.OldInt and e.NewInt to e.OldTime and e.NewTime respectively.

Manifest version format

The manifest.json no longer allows versions in this form:

"Version": {
   "MajorVersion": 1,
   "MinorVersion": 0,
   "PatchVersion": 0,
   "Build": "beta"
}

Versions should be written in the standard string form instead:

"Version": "1.0.0-beta"

Version format

SMAPI no longer omits .0 patch numbers when formatting versions. For example, the console now shows SMAPI 3.0.0 instead of 3.0. That's more standard, improves compatibility with external tools, and reduces player confusion.

This doesn't affect most mod code. You may need to update your code if you use ISemanticVersion.ToString() and compare the output to a hardcoded two-part version string.