Modding:Migrate to Stardew Valley 1.3

From Stardew Valley Wiki
Revision as of 04:03, 14 March 2018 by Pathoschild (talk | contribs) (create page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Axe.png
Article Stub

This article is a stub and is missing information. You can help Stardew Valley Wiki by expanding it!

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 bool dead field is now NetBool dead. 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 NetBool), and a net field is a field with such a type (like Crop.dead).

Usage notes:

  • You can implicitly cast net types to their standard equivalent:
    NetBool a = crop.dead;
    bool b = crop.dead;
    
    if (a == b) // true
    
  • Do not reassign net fields. (Many are readonly to prevent that, but not all.) Instead, set the new value:
    // either of these will work
    crop.dead.Value = true;
    crop.dead.Set(true);
    
  • 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:
    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)