Changes

Jump to navigation Jump to search
→‎Multiplayer concepts: add farmhand shadow world; rename section to "multiplayer concepts for C# mods"
Line 147: Line 147:  
: You can test whether your mod accounts for this correctly by setting the zoom to maximum and the UI scale to minimum (''i.e.,'' have them at opposite values) or vice versa; in particular check any logic which handles pixel positions, like menus clicking.
 
: You can test whether your mod accounts for this correctly by setting the zoom to maximum and the UI scale to minimum (''i.e.,'' have them at opposite values) or vice versa; in particular check any logic which handles pixel positions, like menus clicking.
   −
==Multiplayer concepts==
+
==Multiplayer concepts for C# mods==
 
===Net fields===
 
===Net fields===
 
A 'net type' is any of several classes which Stardew Valley uses to sync data between players, and a 'net field' is any field or property of those types. They're named for the <code>Net</code> prefix in their type names. Net types can represent simple values like <samp>NetBool</samp>, or complex values like <samp>NetFieldDictionary</samp>. The game will regularly collect all the net fields reachable from <samp>Game1.netWorldState</samp> and sync them with other players. That means that many mod changes will be synchronised automatically in multiplayer.
 
A 'net type' is any of several classes which Stardew Valley uses to sync data between players, and a 'net field' is any field or property of those types. They're named for the <code>Net</code> prefix in their type names. Net types can represent simple values like <samp>NetBool</samp>, or complex values like <samp>NetFieldDictionary</samp>. The game will regularly collect all the net fields reachable from <samp>Game1.netWorldState</samp> and sync them with other players. That means that many mod changes will be synchronised automatically in multiplayer.
Line 168: Line 168:  
| Maps <samp>Long</samp>, <samp>Point</samp>, or <samp>Vector2</samp> keys to instances of <samp>TValue</samp> (the underlying value type) and <samp>TNetValue</samp> (the synchronised net type). You can iterate key/value pairs like <code>foreach (KeyValuePair<Long, TValue> pair in field.Pairs)</code> (replacing <samp>Long</samp> with <samp>Point</samp> or <samp>Vector2</samp> if needed).
 
| Maps <samp>Long</samp>, <samp>Point</samp>, or <samp>Vector2</samp> keys to instances of <samp>TValue</samp> (the underlying value type) and <samp>TNetValue</samp> (the synchronised net type). You can iterate key/value pairs like <code>foreach (KeyValuePair<Long, TValue> pair in field.Pairs)</code> (replacing <samp>Long</samp> with <samp>Point</samp> or <samp>Vector2</samp> if needed).
 
|}
 
|}
 +
 +
===Farmhand shadow world===
 +
In [[multiplayer]], secondary players (''farmhands'') don't see most of the in-game locations. Instead their game creates a single-player copy of the world before they join, and then only fetches the [[farm|farm area]] and their current location (called ''active locations'') from the host player. The unsynchronized locations often don't match what players within those locations see.
 +
 +
This has some significant implications for C# mods:
 +
* The <samp>Game1.locations</samp> list shows both active and shadow locations. While mods can access the shadow locations, these don't reflect the real data on the server and any changes to them won't be synced to the host.
 +
* There may be duplicate copies of NPCs, horses, etc in the shadow world. Only those in active locations are 'real'.
 +
* When a farmhand warps to a location, the game fetches the real location from the host player before the warp completes. For a short while, the farmhand may have a null <samp>currentLocation</samp> field while they're between locations.
 +
 +
<br />{{upcoming|1.6|You can check whether a location is active using its <samp>IsActiveLocation</samp> method:
 +
<syntaxhighlight lang="c#">
 +
foreach (GameLocation location in Game1.locations)
 +
{
 +
    if (!location.IsActiveLocation())
 +
        continue; // shadow location
 +
 +
    ...
 +
}
 +
</syntaxhighlight>
 +
}}
    
==Assets==
 
==Assets==
translators
8,437

edits

Navigation menu