Changes

Jump to navigation Jump to search
create page
{{stub}}

'''This page is for modders. Players: see [[Modding:SMAPI compatibility]] instead.'''

This page explains the most common changes needed in mods for compatibility with Stardew Valley 1.3.

==SMAPI mods==
===Net types===
Stardew Valley 1.3 uses a new set of C# types to synchronise data between players. For example, a crop's <tt>bool dead</tt> field is now <tt>NetBool dead</tt>. The game will intermittently get the value of all reachable net fields, and send them to the other players. A ''net type'' means a network-synchronised type (like <tt>NetBool</tt>), and a ''net field'' is a field with such a type (like <tt>Crop.dead</tt>).

Usage notes:
<ul>
<li>You can implicitly cast net types to their standard equivalent:
<source lang="c#">
NetBool a = crop.dead;
bool b = crop.dead;

if (a == b) // true
</source>
</li>
<li>'''Do not''' reassign net fields. (Many are readonly to prevent that, but not all.) Instead, set the new value:
<source lang="c#">
// either of these will work
crop.dead.Value = true;
crop.dead.Set(true);
</source></li>
<li>Net types can't handle implicit casting for value types when using null-conditional operators. Always check for null before comparing or implicitly casting to a value type:
<source lang="c#">
Crop crop = null;

// all of these crash: 'System.NullReferenceException' in Netcode.dll
bool deadA = crop?.dead;
bool? deadB = crop?.dead;
if (crop?.dead == true)

// this are okay
if (crop?.dead != null && crop?.dead == true)
</source></li>
</ul>

[[Category:Modding]]
translators
8,447

edits

Navigation menu